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
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