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.
0 个评论
采纳的回答
更多回答(1 个)
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...
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!