필터 지우기
필터 지우기

How can I change legend colors if I have multiple graphs of the same color?

조회 수: 2 (최근 30일)
I'm plotting 10 funtcions in the same graph, 5 of one type in red and 5 of another type in blue.
I would like to create a legend where there is a red line that says "Type1" and a blue line that says "Type2".
I didn't find a way to do that since the lengend is expecting 10 names, and if I put only two of them, those are both red.

채택된 답변

Sachin Shrestha
Sachin Shrestha 2016년 6월 11일
Hi Leonardo,
You may specify the handles of the plots for which you want to have the legend. In your case, you may specify handles, one for red line and another for blue line and generate legends for those only. For instance:
handle1=plot(1:10,'r'); % define handle for one of the red lines
hold on;
plot(1:2:20,'r');
plot(1:3:30,'r');
plot(1:4:40,'r');
plot(1:5:50,'r');
handle2=plot(3:10,'b'); % define handle for one of the blue lines
plot(3:2:20,'b');
plot(3:3:30,'b');
plot(3:4:40,'b');
plot(3:5:50,'b');
legend([handle1 handle2],{'type1','type2'}); % define legend for plots related to handles
Hope this helps. Good Luck!

추가 답변 (0개)

카테고리

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