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

8 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2018-11-15
编辑:Walter Roberson 2018-11-15
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 个评论
Walter Roberson
Walter Roberson 2018-11-15
% 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 2018-11-15
@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.

请先登录,再进行评论。

更多回答(1 个)

KSSV
KSSV 2018-11-15
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 个评论
Kien Pham
Kien Pham 2018-11-15
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by