필터 지우기
필터 지우기

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 CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by