I am working on a Matlab project in which I need to use the fill
command. The fill
command fill(X,Y,C) creates filled polygons from the data in X and Y with vertex color specified by C.
I've got the following code:
x_2 = [x, fliplr(x)];
inBetween = [Auf1_mW_pro_mg(1781:length(Auf1_mW_pro_mg)), fliplr(y_Temp)];
figure('Name','Test')
fill(x_2, inBetween, 'r','facealpha',.5,'LineStyle','none');
legend()
... ,which gets me this result:
As you can see I've got two areas because my data is real data and the extrapolated line does not always only have the data-line above it.
Does anybody have a simple idea how to avoid two data elements being displayed in the legend in this scenario? Deleting elements form the legend does not seem to be something that is easily accomplished, which was my first idea. Maybe I can get control over which data is added to the legend?
Thank you!
If fill
shows up twice in the legend, two patches are created. You can set the visibility of these individual patches for the legend
. First store the handles of the graphics objects
h = fill(x_2, inBetween, 'r','facealpha',.5,'LineStyle','none');
This will return a 2×1 Patch array, of which you can set the HandleVisibility
property for the second element:
h(2).HandleVisibility = 'off';
Now it won't show in your legend. But functions like findobj
also cannot find the patch, more details on the consequences here).