フィルターのクリア

Legend Button displays data1, data2, etc

20 ビュー (過去 30 日間)
Scott
Scott 2014 年 1 月 9 日
コメント済み: Steven Lord 2017 年 5 月 5 日
Hi,
I've been searching for a while and I'm hoping someone can help me figure this out.
How can I make the legend button in the figure toolbar display the data by name instead of 'data1,data2,data3,etc'?
I've set the 'Tag' property for each lineseries to what I want displayed in the legend.
Is there a way to change the callback function for icons such as the legend button in the default toolbar?
Thanks so much,
Scott

回答 (1 件)

KAE
KAE 2017 年 5 月 4 日
You need to include strings in the legend command.
% Plot some data
figure;
h1 = plot(rand(1,7), rand(1,7));
hold on;
h2 = plot(rand(1,7), rand(1,7));
h3 = plot(rand(1,7), rand(1,7));
% Label each line in the legend
legend([h1 h2 h3], 'First line', 'Second line', 'Third line');
  1 件のコメント
Steven Lord
Steven Lord 2017 年 5 月 5 日
That's one way. Another, as stated in the legend function documentation, is:
"legend('show') creates a legend for the current axes or chart returned by gca. The legend automatically updates when you add or delete graphics objects from the axes. For the labels, the legend uses the text from the DisplayName properties of the graphics objects. If the DisplayName property is empty, then the legend uses a label of the form 'dataN'."
So you could assign a value to the DisplayName property of the graphics object when you construct it (or afterwards) and legend will use that value.

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

カテゴリ

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