필터 지우기
필터 지우기

Color mismatch between legend and plots

조회 수: 2 (최근 30일)
Joshua
Joshua 2014년 5월 16일
답변: Image Analyst 2014년 5월 17일
I am plotting 6 data vectors and a legend. The first 4 components of the legend have the correct color (matches the plotted colors). However, the last 2 components of the legend are incorrect. They have the same color as the first (and fourth) data vector.
Here is my code.
figure()
hold on
% plotting Leone et al. 2011 geotherm
plot(T_leone10,z_leone,'r+','LineWidth',2)
% plotting Leone et al. 2011 geotherm
plot(T_leone30,z_leone,'b+','LineWidth',2)
% plotting Leone et al. 2011 geotherm
plot(T_leone50,z_leone,'g+','LineWidth',2)
% plotting my geotherm
plot(T{2},z,'r-','LineWidth',2)
plot(T{3},z,'b-','LineWidth',2)
plot(T{4},z,'g-','LineWidth',2)
% labeling the graph and creating the legend
xlabel('Temperature in kelvin')
ylabel('Depth in meters')
title({['Leone et al. 2011 vs. Knicely : QUICK'];['z_c = ',num2str(z_c),' meters']})
grid on
legend('Leone et al. 2011 - 0.1 porosity','Leone et al. 2011 - 0.3 porosity', ...
'Leone et al. 2011 - 0.5 porosity','Knicely (2014) - 0.1 porosity', ...
'Knicely (2014) - 0.3 porosity','Knicely (2014) - 0.5 porosity',0)

답변 (2개)

Star Strider
Star Strider 2014년 5월 16일
You may have to specify the colours for your lines individually using colormap. It’s not difficult — most colormaps have 64 colours or levels, addressable by index (so you don’t have to specify the 3-element colour vector) — but it does take some experimenting to learn to use it effectively.

Image Analyst
Image Analyst 2014년 5월 17일
Perhaps you need to post your data because this seems to work for me:
x1 = sort(rand(1,10));
x2 = sort(rand(1,10));
x3 = sort(rand(1,10));
x4 = sort(rand(1,10));
x5 = sort(rand(1,10));
x6 = sort(rand(1,10));
y1 = rand(1,10);
y2 = rand(1,10);
y3 = rand(1,10);
y4 = rand(1,10);
y5 = rand(1,10);
y6 = rand(1,10);
% plotting Leone et al. 2011 geotherm
plot(x1,y1,'r+','LineWidth',2)
% plotting Leone et al. 2011 geotherm
plot(x2,y2,'b+','LineWidth',2)
% plotting Leone et al. 2011 geotherm
plot(x3,y3,'g+','LineWidth',2)
% plotting my geotherm
plot(x4,y4,'r-','LineWidth',2)
plot(x5,y5,'b-','LineWidth',2)
plot(x6,y6,'g-','LineWidth',2)
% labeling the graph and creating the legend
xlabel('Temperature in kelvin')
ylabel('Depth in meters')
title('6 plots')
grid on
legend('Leone et al. 2011 - 0.1 porosity','Leone et al. 2011 - 0.3 porosity', ...
'Leone et al. 2011 - 0.5 porosity','Knicely (2014) - 0.1 porosity', ...
'Knicely (2014) - 0.3 porosity','Knicely (2014) - 0.5 porosity',0)
However, I do know that sometimes the legend doesn't match the data - I've experienced that myself here: http://www.mathworks.com/matlabcentral/answers/127613#comment_210970. Also, see Frederich's answer to my comment.

카테고리

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