Legends not matching colors

33 次查看(过去 30 天)
Sachin Motwani
Sachin Motwani 2020-10-29
My legends are not matching the colors I labeled.
Yu = rand(1000, 1);
Yn = randn(1000, 1);
plot(Yn,'g'), hold on, plot(Yu, 'r'), title('Random noise over time'), legend('Normal',"Uniform");
  2 个评论
Andrew Newell
Andrew Newell 2020-10-29
But they do match: The uniform distribution is Yu and it is plotted with a red line.
Sachin Motwani
Sachin Motwani 2020-10-29
But what about green which is displayed as blue.

请先登录,再进行评论。

回答(1 个)

Kelly Kearney
Kelly Kearney 2020-10-29
Are you certain that those are the only plotting commands? Did you perhaps test plot once with hold on, then call your commands again? Unless you specify handles, the legend command will just label objects in plotting order.
Your code should work fine:
Yu = rand(1000, 1);
Yn = randn(1000, 1);
figure;
plot(Yn,'g');
hold on;
plot(Yu, 'r');
title('Random noise over time');
legend('Normal','Uniform');% place..
But if perhaps you added some extra plotting...
figure;
hold on;
plot(Yn); plot(Yu); % plotting once
plot(Yn,'g'); % and twice
hold on;
plot(Yu, 'r');
title('Random noise over time');
legend('Normal','Uniform');% place..

类别

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

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by