omit plot legend entries
23 次查看(过去 30 天)
显示 更早的评论
Within a loop I am creating fittings for a set of data. At the same time I am plotting the fitting curves and the data set with markers. How do I prevent the markers and small dots from showing within the legend? I only want the line color for each curve fitting to show up. There is one legend entry for each fit.
Thanks in advance!

0 个评论
采纳的回答
Voss
2022-1-5
One way is to store the handles to your lines as you create them and make a legend based on a subset of the lines:
figure();
my_lines = [];
my_lines(end+1) = plot(1:10);
hold on
my_lines(end+1) = plot(2:11);
my_lines(end+1) = plot(3:12);
legend(my_lines([1 3]),{'first' 'third'});
A similar way is to only store those handles you want to use in the legend:
figure();
my_lines = [];
my_lines(end+1) = plot(1:10);
hold on
plot(2:11);
my_lines(end+1) = plot(3:12);
legend(my_lines,{'first' 'third'});
更多回答(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!

