Legend Button displays data1, data2, etc
조회 수: 20 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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
2017년 5월 5일
"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 Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!