Matlab 2018 - Figure legend swamped by data2, data3, data4,... used to be able to just put single legend entry.. how to revert to previous behavior?

조회 수: 2 (최근 30일)
In updgrading to Matlab 2018 all my figure legends are broken. I use to use legend once for many lines from the same data. Current matlab legend help states "The legend automatically updates when you add or delete data series from the axes". This is true as now my legends are swamped even if I only call the legend after plotting a single line. How to have a limited number of legend labels, say 2, even when plotting 100's of lines on a figure.
A snippet of ugly code that used to work well for me, but now generates line 1 of a legend as I want and then data2, data3, ... datan..
for i=1:length(ids)
plot(D{ids(i)},V{ids(i)},'k')
if i==1
hold on
legend('WSP','Location','Northwest')
end
end
hold off
Any help appreciated.

채택된 답변

Jan
Jan 2019년 1월 31일
편집: Jan 2019년 1월 31일
Do you mean:
legend('WSP', 'Location', 'Northwest', 'AutoUpdate', 'off')
  댓글 수: 2
Benjamin Schafer
Benjamin Schafer 2019년 1월 31일
Excellent, thank you. will add that to all my new files that are having this problem.
Can the default legend propterty be changed in the beginning of a script so that my old code would still work without modification? (I know this is asking a lot.. )

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Tolga Karabiyikoglu
Tolga Karabiyikoglu 2025년 1월 23일
Here is another option for you,
First define handles for the plots you want to see on your legend. It would be easy if you have a loop to generate your plots on the same axes.
Next continue your ploting code with a snippet as follows;
legend(HandleOfTheAxes, [HandleOfThePlotsToLegend], 'Location', 'northeast'); or issue a line like
legend(gca, [HandleOfThePlotsToLegend], 'Location', 'northeast');
as you donot have defined a handle to your axes before...

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by