Can MATLAB legend color order be changed as the legend element order changes?
显示 更早的评论
Using the following code from the 'Specify Legend Descriptions During Line Creation' example in MATLAB help, I've created the following plot:

I've successfully changed the order of the legends entries using the following steps:
1. Clicked the arrow button so I could select the legend
2. Double clicked on the legend
3. Selected More Properties from the property editor
4. Selected the 'String' property and re-ordered the elements of the legend

The order of the legend elements did change. However, the associated color scheme did not.
Is there a separate function for this? Can the color order be changed as well?
Thanks.
采纳的回答
更多回答(2 个)
Joseph Cheng
2015-6-15
0 个投票
I'll start off with Yes it can be done, and No there is not a separate function. What you did by double clicking is not changing the assignment but just the displayed text. There is some trickery to change the color, positioning, text, etc of a legend I would say it is much easier to just follow the documentation on legend than dig into its parameters. Plot the lines in the order you want to display it in the legend and label the lines using legend() appropriately.
2 个评论
Brad
2015-6-16
Joseph Cheng
2015-6-16
legend element is tied to the displayed line (color, marker type, line style, etc.). If they are not and are mixed up I would say there is 99% your inputs to the legend function is probably in the wrong order.
类别
在 帮助中心 和 File Exchange 中查找有关 Legend 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!