So I am plotting the same variable 3 times within one figure that's parameters change with simulink. It produces 3 lines but the problem is, the 3 lines are the same color even though I specify each of the plots to be different linewidth, color and legend. It produces the very last specific color values.
I tried the following
plot(t,x, 'Color', 'Black', 'Linewidth', 2);
legend('Black');
hold on;
plot(t,x, 'Color', 'Cyan', 'Linewidth', 2);
legend('Cyan');
hold on;
plot(t,x, 'Color', 'Blue', 'Linewidth', 2);
legend('Blue');
All the lines on the graph show up as Blue even though I specified different colors/legend for each of the lines.

 채택된 답변

Image Analyst
Image Analyst 2018년 3월 19일

0 개 추천

Try this
plot(t, x, 'k-', 'LineWidth', 2);
hold on;
plot(t, x, 'c-', 'LineWidth', 2);
plot(t, x, 'b-', 'LineWidth', 2);
legend('Black', 'Cyan', 'Blue');

댓글 수: 5

Brandon Luciano
Brandon Luciano 2018년 3월 19일
Still get the same last color entered for all which is blue in this case.
Image Analyst
Image Analyst 2018년 3월 19일
That's because all plots are on top of each other because you're plotting the same thing 3 times. So either make the first plots have a thicker LineWidth (like 5, then 3, then 1), or plot x1 in the first call to plot(), x2 in the second call to plot(), and x3 in the third call to plot(), not x every single time.
Brandon Luciano
Brandon Luciano 2018년 3월 20일
I realize I am plotting the same variable but the variable is dependent on a block diagram defined in Simulink which results in the graph displaying 4 unique lines. They aren't the same line overlayed but rather 4 lines at different points.
By changing the variable x1, this will break the block diagram functionality, that's why I was wondering if there's a way to avoid that.
I will settle for that the random 4 colors MATLAB assigns and just leave the linewidth.
Image Analyst
Image Analyst 2018년 3월 20일
You can set the default color order if you want so the colors are not "random". See attached demo.
Brandon Luciano
Brandon Luciano 2018년 3월 20일
Thank you. This was helpful.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Scatter Plots에 대해 자세히 알아보기

질문:

2018년 3월 19일

댓글:

2018년 3월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by