Adding to a legend after each iteration

前端 未结 5 1629
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 15:13

I run

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

from the first script. Then, hold on;. I run a similar second script. I see two g

5条回答
  •  遥遥无期
    2020-12-17 16:01

    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!

    For more information see this: dynamic legend from undocumented matlab

    EDIT

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

提交回复
热议问题