change the color of data in legend
조회 수: 72 (최근 30일)
이전 댓글 표시
I have 3 plots on the same figure but legend doesn't show the right color for each plot.
y=1:10;
color_=['r', 'b'];
for i=1:2
if i==1
j=1;
elseif i==2
j=6;
end
plot(y(j:j+4),color_(i));
hold on
plot([0 10],[5 5],'g');
end
legend('plot1','plot2','line');
댓글 수: 0
채택된 답변
Walter Roberson
2011년 6월 21일
h1 = plot(x1,y1,'r');
hold on
h2 = plot(x2,y2,'b');
legend([h1,h2],'plot1','plot2')
The line color used for legend() will be the same as the line color used on the graph.
추가 답변 (1개)
Fangjun Jiang
2011년 6월 21일
댓글 수: 14
aerothermal
2016년 8월 31일
Same answer of https://www.mathworks.com/matlabcentral/answers/146668-legend-and-graph-doesn-t-have-the-same-color
By the way, nice work!
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!