Legend color is different with plot color.

I have four different plots in a single figure, the problem what I get is in the legend four of them assigned by the same color which I don't want and not correct, the plots are in different colors though. please If someone can help me on how to solve this problem. To make clear you can look the peace of code.
b=2;s=3;
plot(tt,Detection_2(:,1,1),'rs','Linewidth',2,'MarkerSize',8);hold on;
plot(tt,Detection_3(:,1,1),'y+','Linewidth',2,'MarkerSize',8);hold on;
plot(tt,Detection_4(:,1,1),'gs','Linewidth',2,'MarkerSize',8);hold on;
plot(tt,Detection_5(:,1,1),'m+','Linewidth',2,'MarkerSize',8);
l=legend('2-Targets','3-Targets','4-Targets','5-Targets');
set(gca,'FontSize',12);
grid MINOR
set(x,'Interpreter','latex','FontSize',12);
set(y,'Interpreter','latex','FontSize',12);
set(l,'Interpreter','latex','FontSize',12,'Location','southwest');
pbaspect([1 1 1])
set(gcf, 'Color', 'w');
export_fig figPf.pdf

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 5 月 28 日

0 投票

That could happen if tt is a 2D array with at least 4 columns, as that would trigger the first plot() call to create one line for every column of tt. (Side note: it might be rows that is the problem instead of columns: plot() will automatically match the dimension of tt with the dimension of Detection_2(:,1,1) )

4 件のコメント

Abebe Haftu Fitur
Abebe Haftu Fitur 2018 年 5 月 28 日
The plot is working fine there is no wrong with it, I am getting correctly plotted values. The problem is with legend colors, it gives me only one color for four of them, while the plots are in four different colors. plus 'tt' is a vector, all of the four values have the same length.
Walter Roberson
Walter Roberson 2018 年 5 月 28 日
Which MATLAB release are you using, and which operating system? What is the output of
opengl info
Abebe Haftu Fitur
Abebe Haftu Fitur 2018 年 5 月 28 日
2017B and Windows 10.
Walter Roberson
Walter Roberson 2018 年 5 月 28 日
Are you using Intel HD 3000 graphics card?

サインインしてコメントする。

カテゴリ

質問済み:

2018 年 5 月 28 日

コメント済み:

2018 年 5 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by