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

조회 수: 14 (최근 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에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by