How to remove interpolated FaceColor from Legend of multiple surface plots?
7 views (last 30 days)
Show older comments
I have a plot of two surfaces. I was able to distinguish them using LineStyle, and I want FaceColor of both surfaces to be interpolated via 'interp.' Now, when I create a Legend of this plot, MATLAB just picks a single color for each of the Surface. It is unclear the criteria used to pick this color. I rather to not have the face colors at all in the legend. Can I turn them off? Or change the FaceColor to white in the Legend only?
My code:
plt_sf1 = surf(a,data1,data2,'linestyle','-.',...
'facecolor','interp','facealpha',0.7,'linewidth',1.4); hold on;
plt_sf2 = surf(a,data1,data3,'facecolor','interp'); hold off;
lg_sf = legend([plt_sf1, plt_sf2],{'text', 'text'});
set(lg_sf,'color','none','box','off','facecolor','red');
I was hoping to be able to do the following:
set(lg_sf,'FaceColor','none')
But that gave an error saying there is no FaceColor properties for Legend. But clearly there is. I just can't control it.
Any help is appreciated. Thanks.
0 Comments
Accepted Answer
Walter Roberson
on 15 Nov 2018
Edited: Walter Roberson
on 15 Nov 2018
In cases where you want a legend that does not match the automatic legend rules, it is often easier to create some dummy invisible graphics objects that have the properties that you would like to have show up, and legend those instead . Sometimes there are ways to get the desired outputs by changing properties after calling legend but it is not clear that it is worth the fight at times .
3 Comments
Walter Roberson
on 15 Nov 2018
% don't legend the original objects, legend objects that
% have nice properties but are not on-screen because their
% locations are empty or are nan or are inf
plt_sf1_L = surf([],[],[],'linestyle','-.',...
'facecolor','none','facealpha',0.7,'linewidth',1.4);
plt_sf2_L = surf([],[],[],'facecolor','none');
lg_sf = legend([plt_sf1_L, plt_sf2_L],{'text', 'text'});
More Answers (1)
KSSV
on 15 Nov 2018
This might be due to using two colormaps on the same figure. YOu need to follow something like this given in the link: https://in.mathworks.com/matlabcentral/answers/101346-how-do-i-use-multiple-colormaps-in-a-single-figure
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!