How to remove interpolated FaceColor from Legend of multiple surface plots?

7 views (last 30 days)
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.

Accepted Answer

Walter Roberson
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
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'});
Kien Pham
Kien Pham on 15 Nov 2018
@Waterl Robertson, it worked!! The only thing I had to add was 'hold on' and 'hold off' to make sure the fake plots weren't overwritten by the actual plots. Thank you.

Sign in to comment.

More Answers (1)

KSSV
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
  1 Comment
Kien Pham
Kien Pham on 15 Nov 2018
Hi @KSSV, Thank for the response. I followed your link. It listed examples of how to use more than one colormaps but did not discuss enforcing the use of one colormap. I am not even sure if enforcing one colormap would answer my question on how to turn off the colormap in the Legend box. That's what I want to accomplish here.

Sign in to comment.

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!