Hello,
I would like to ask you about the limitations of yyaxis plots in a single plot. I've noticed that if the number of lines is greater than four, the last line is plotted extremely bold, regardless of the settings. I am using MATLAB R2023b.
I've included an example below for testing.
x = -pi:0.01:pi;
figure(1)
lineColor = turbo(5);
for iSin = 1:5
yyaxis left
plot(x, sin(iSin * x), 'LineStyle', '--', 'LineWidth', 1.5, 'Color', lineColor(iSin, :))
hold on
end
The picture with 5 elements:
The picture with 4 elements:
Is this a bug or some limitations of yyaxis command?
Thanks in advance.
Best regards,
Filip Lekes.

 채택된 답변

Star Strider
Star Strider 2025년 3월 26일

0 개 추천

I doubt that it is a limitation, simply yyaxis doing its best to make the lines distinct. You can specify them yourself with the LineSpec options (although it would likely be best to not specify the colours, and let yyaxis define that).

댓글 수: 4

Filip Lekes
Filip Lekes 2025년 3월 26일
If you would like to plot multiple lines using yyaxis, is there no option to manage the colors?
Is there a workaround or a different command to plot multiple plots with two y-axes?
Thanks.
Star Strider
Star Strider 2025년 3월 26일
You can certainly define the colours yourself. It would be best to also use the DisplayName option and legend in that instance.
The yyaxis function chooses the colours so that associating the curves with the appropriate y-axis is more straightforward.
I've just tried this approach with LineSpec and works as I would expected.
plot(x, sin(iSin * x), '--', 'LineWidth', 1.5, 'Color', lineColor(iSin, :))
It's funny that without 'LineStyle' it's working.
Thanks a lot for support.
Star Strider
Star Strider 2025년 3월 26일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

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

추가 답변 (1개)

Adam Danz
Adam Danz 2025년 3월 26일

1 개 추천

Specify Line Style and Color in axes properties instead of in plot(__)
Starting in R2023a, you can set the line style and line colors in axes properties and you can control how the axes cycles through those line and color properties as new objects are added to the axes.
The following block uses these axes properties to control the color and style of the lines.
  • LineStyleOrder
  • ColorOrder
  • LineStyleCyclingMethod
x = -pi:0.01:pi;
figure(1)
yyaxis left
ax = gca();
ax.ColorOrder = turbo(5);
ax.LineStyleOrder = '--';
ax.LineStyleCyclingMethod = 'withcolor'; % cycle through linestyle and color together
hold on
for iSin = 1:5
plot(x, sin(iSin * x), 'LineWidth', 1.5)
end

카테고리

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

제품

릴리스

R2023b

태그

질문:

2025년 3월 26일

답변:

2025년 3월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by