Get lineseries handle

2 ビュー (過去 30 日間)
Jared
Jared 2011 年 11 月 3 日
I'm trying to use set to set the display name of each legend label.
If I have:
h=plot();
Then try to do:
set(h(1),'DisplayName','data label')
It's not working. Do I have to set the legend to be displayed first or does this automatically display it then change the label of each data series?

採用された回答

Patrick Kalita
Patrick Kalita 2011 年 11 月 3 日
Setting the DisplayName property does not automatically show the legend. You still need to explicitly show the legend:
h = plot( 1:5, rand(1,5), 6:10, rand(1,5) );
set(h(1), 'DisplayName', 'some data');
set(h(2), 'DisplayName', 'more data');
legend show

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2011 年 11 月 3 日
If you want to change the legend, get the handle of the legend, or simply run legend() again.
plot(magic(3));
legend({'a','b','c'});
h=legend({'1','2','3'});
set(h,'string',{'first','second','third'});

カテゴリ

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