随笔 - 744  文章 - 1  评论 - 61 

matlab的figure添加图例

 

 

x = linspace(0,pi);
y1 = cos(x);
plot(x,y1)

hold on
y2 = cos(2*x);
plot(x,y2)

y3 = cos(3*x);
plot(x,y3)

y4 = cos(4*x);
plot(x,y4)
hold off

legend({'cos(x)','cos(2x)','cos(3x)','cos(4x)'},'Location','northwest','NumColumns',2,'FontSize',12,)

 如果不想显示某一个图例,可以参考以下代码:

figure(1);hold on;hi=plot([val_g,val_g],[0,g(val_g)],'r-','linewidth',1);
set(hi(1),'handlevisibility','off');

https://www.mathworks.com/help/matlab/ref/legend.html

posted on 2020-08-02 15:54  一杯明月  阅读(90)  评论(0编辑  收藏