MATLAB graph plotting: assigning legend labels during plot

前端 未结 5 780
傲寒
傲寒 2020-12-29 12:11

I am plotting data in a typical MATLAB scatterplot format. Ordinarily when plotting multiple datasets, I would use the command \'hold on;\', and then plot each of the data,

5条回答
  •  一向
    一向 (楼主)
    2020-12-29 12:21

    You should be able to set the DisplayName property for each plot:

    figure
    hold on
    plot(...,'DisplayName','DataSet1')
    plot(...,'DisplayName','DataSet2')
    legend(gca,'show')
    

    http://www.mathworks.com/help/matlab/ref/line_props.html

    Side Note: I've found a lot of little tricks like this by getting the figure to look the way I want, then choosing the Figure's "File" menu option "Generate M-File..." and inspecting the generated output code.

提交回复
热议问题