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

19 ビュー (過去 30 日間)
Kien Pham
Kien Pham 2018 年 11 月 14 日
コメント済み: Kien Pham 2018 年 11 月 15 日
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 Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by