yyaxis limit for lines in one graph
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Filip Lekes
am 26 Mär. 2025
Beantwortet: Adam Danz
am 26 Mär. 2025
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.
0 Kommentare
Akzeptierte Antwort
Star Strider
am 26 Mär. 2025
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 Kommentare
Star Strider
am 26 Mär. 2025
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
Weitere Antworten (1)
Adam Danz
am 26 Mär. 2025
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
