How to not include an item in a legend

50 ビュー (過去 30 日間)
Jason
Jason 2015 年 1 月 5 日
コメント済み: Jason 2015 年 1 月 5 日
Is it possible to change whats displayed on a legend. Im plotting 3 data sets, but data set 1 and 2 are the same, only that data set 2 plots over dataset 1 with a black box if a certain condition is met.
I therefore want to remove dataset2 from the legend?
Thanks for any pointers

採用された回答

Jason
Jason 2015 年 1 月 5 日
Done it...
For dataset1 use
h1=plot....
for dataset2
h2=plot....
and for dataset3
h3=plot
then use
legend([h1,h3],'item1','items2','Location','bestoutside','Orientation','horizontal')

その他の回答 (3 件)

Julian Hapke
Julian Hapke 2015 年 1 月 5 日
ok, here's the solution: you can tell legend() with which plot handle the legend entry is associated, by:
clf;
plot(rand(10,4));
a=get(gca,'Children');
legend([a(4);a(1)],{'bla','bli'})
note that the first created plot is at the last index of the children array
regards
  2 件のコメント
Julian Hapke
Julian Hapke 2015 年 1 月 5 日
ooops, a bit too late
Jason
Jason 2015 年 1 月 5 日
Thankyou for you time anyway. Jason

サインインしてコメントする。


Julian Hapke
Julian Hapke 2015 年 1 月 5 日
you could add the data set with the black boxes at last and then only define 2 legend entries.

Jason
Jason 2015 年 1 月 5 日
編集済み: Jason 2015 年 1 月 5 日
I tried that first. My first data set is big squares in blue.(dataset1)
If a condition is reached, then I want these squares to be red or black (represent extremes).I then plot again within an if/elseif statement. This is my dataset 2 (that I don't want on the legend)
I then plot a green Cross ontop of the squares for another data set (dataset3).If I do your suggestion, then the crosses are not seen.
I've tried this approach by calling my dataset 2 via
h2=plot.....
hsAnno = get(h2, 'Annotation');
hsLegend = get(hsAnno, 'LegendInformation');
set(hsLegend, 'IconDisplayStyle', 'off');
But no joy

カテゴリ

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