每次迭代后添加到图例 [英] Adding to a legend after each iteration

查看:88
本文介绍了每次迭代后添加到图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跑步

loglog(x,y);
legend('First script');

从第一个脚本开始. 然后,hold on;. 我运行类似的第二个脚本. 我可以正确看到两个图形,但只能看到初始图例. 我想从不同的脚本中增加图例.

from the first script. Then, hold on;. I run a similar second script. I see two graphs correctly, but only the initial legend. I want to increment the legend from different scripts.

如何从单个脚本添加到图例?

推荐答案

执行此操作的另一种可能的方法称为"DisplayName":

Another possible way to do this and it is called 'DisplayName':

hold all
for ind=1:3
x=[0:0.1:10];
plot(x, sin(x)+ind, 'DisplayName',['sin + ' num2str(ind)]);
end
legend(gca,'show')

从任何地方绘制到任何轴时都只需使用此属性:)

Just use this property when plotting from wherever to whatever axes :)

还有更多可能,例如动态图例!

There are even more things possible, like dynamic legend!

有关更多信息,请参见:来自未记录的Matlab的动态图例

For more information see this: dynamic legend from undocumented matlab

编辑

您必须在每次运行脚本后更新图例.您可以使用动态图例或仅通过legend('off')来完成此操作;图例(显示")

you have to update the legend after every run of a script. you can do this with the dynamic legend or by just legend('off'); legend('show')

这篇关于每次迭代后添加到图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆