how to change the sequence of the legend

大兔子大兔子 提交于 2019-12-11 03:13:59

问题


I want to change the sequence of the legend.

See the figure. I want the sequence to be: green and data2, blue and data3, black and data4, red and data1.

Could anyone give a demo?


回答1:


Change the order in which the plots are added to the figure, and then call legend normally. That should do it.


You can also do it as follows. First get handles to the individual plots:

h1 = plot(1:5);
hold on
h2 = plot(11:15, 'r');

Then call legend specifying the order:

legend([h1 h2],'plot1','plot2')

or

legend([h2 h1],'plot2','plot1')




回答2:


In case, you have already made the plots or if you added some plot at the end, which want to reorder to somewhere in middle, you can try this way:

1) Go to show Plot Tools and Dock Figure.

2) Delete the data (which you want to move to bottom). Then undo delete.

3) Refresh legend.



来源:https://stackoverflow.com/questions/22734177/how-to-change-the-sequence-of-the-legend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!