Plot lables with hold on

11 次查看(过去 30 天)
Jalali
Jalali 2012-6-24
plot(R, ':.b') %blue
xlabel('Time')
ylabel('Dollar')
hold all
plot(L, '-.g') %green
plot(D, '--r') %red
I'm using hold all to plot R, D, and L as shown above. How can I show a label for each one with the same color, using 'legend'? Any other suggestion would be appreciated! :)
Thanks,

回答(1 个)

Walter Roberson
Walter Roberson 2012-6-24
You want the colors in the legend to be all the same as each other ("the same color"), or you want the colors in the legend to correspond to the line colors?
If you want the colors in legend to correspond to the line colors, just call legend() and specify the labels: it will automatically use the line colors that were used in the plotting.
  3 个评论
Walter Roberson
Walter Roberson 2012-6-24
Call legend() after all three plot() commands have been done: it should use the corresponding colors.
For deeper darker details on legend(), see http://www.mathworks.com/help/techdoc/creating_plots/braliom.html
Jalali
Jalali 2012-6-24
I called legend() after all three plot() commands but still the first one is shown.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by