Can the same axis scaling be obtained for the left and right y axes using "yyaxis" in MATLAB R2024a?
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 15 Ott 2025 alle 0:00
Risposto: MathWorks Support Team
il 21 Ott 2025 alle 20:39
When I execute the command "yyaxis right", the right y-axis is a different color and scale than the left y-axis.
How can I use the “yyaxis” function to create a right y-axis that is identical in color and scale to the left y-axis?
Risposta accettata
MathWorks Support Team
il 15 Ott 2025 alle 0:00
While there is no “yyaxis” input argument or single MATLAB function that will create identical left and right axes, a workaround is to create a right axis using properties of the existing left axis. For example, instead of executing "yyaxis right", the following two lines of code can be used:
hL = gca; hR = axes('YLim', hL.YLim, 'YTick', hL.YTick, 'YTickLabels', hL.YTickLabels, ... 'XTick', [], 'YAxisLocation', 'right', 'Color', 'none');
Here, “hL” is a handle to the existing left axis, and “hR” is a handle to the newly created right axis. Since “hR” is created with the same y-axis limits, tick values, and tick labels as “hL”, the resulting right y-axis should appear identical to the left y-axis.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Axis Labels in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!