Color mismatch between legend and plots

4 ビュー (過去 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 Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by