Legends not matching colors

조회 수: 32 (최근 30일)
Sachin Motwani
Sachin Motwani 2020년 10월 29일
답변: Kelly Kearney 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