首页 > 解决方案 > How do I add a box explaining which line belongs to which function?

问题描述

I want to make a plot showing the plots of two different functions. One of them is plotted using a continuous line while the other is drawn using a dashed line. I want to have a box that says something like

- - f(x)
----- g(x)

to explain which function is drawn with which line. How do I do this?

Thanks in advance

标签: plotoctave

解决方案


我建议您查看有关绘图注释的文档。就您而言,该legend功能就是您要寻找的功能。请参见以下示例:

>> a = [1 2 3 4 5];
>> b = sin(a);c = cos(a);
>> plot(a,b,'--',a,c,'-*')
>> legend('sin(a)','cos(a)')

图例显示不同的情节风格


推荐阅读