How can I hold the previous "legend" on a plot?
조회 수: 294 (최근 30일)
이전 댓글 표시
I use the "hold" function to hold the previous plots. But how can I hold the previous legends, too?
댓글 수: 0
채택된 답변
sadel
2011년 6월 17일
댓글 수: 6
Harshia Mathur
2021년 9월 28일
worked for me as well, Do you know anyway to customise this? I want to append a string, otherwise all it's saying is data1 , data2 etc..
Walter Roberson
2021년 9월 28일
@Harshia Mathur example
x=0:.01:10;
for alpha = [1 5 9]
plot(x, nthroot(sin(x).^alpha,7), 'DisplayName', "sin^{" + (alpha/7) + "}");
hold on;
end
hold off
ylim auto
legend show
추가 답변 (3개)
Gerd
2011년 6월 14일
For example I you would like to show the sin and cos you would use
t=[0:0.1:10]
x=sin(t)
y=cos(t)
plot(t,x)
hold
plot(t,y,'r')
legend('sin','cos')
In your case you have to build the legendstring with the two different "strings" you want to show.
댓글 수: 0
Gerd
2011년 6월 14일
Hi sadel, to get the current legend use
% you have to have a legend on the current plot
get(legend(gca),'String'); % get legend from current axes.
% Now you can set the legend of the new plot
Gerd
댓글 수: 5
Rajani Metri
2020년 12월 5일
Hello,
but legend holding only text. It is showing legend indicators as lines, instead of asteric lines, which I used. It is not holding the marking points of plots. For holding Marker points of respective plots, what to do?
Thank You.
Walter Roberson
2020년 12월 5일
Which MATLAB version are you using? And please explain what you are trying to do in more detail?
Andrea Cavallini
2018년 2월 6일
Quick and dirty... at last (before hold off), draw something out of the scope of the plot, but with the right legend symbols. That will do
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!