Can the same axis scaling be obtained for the left and right y axes using "yyaxis" in MATLAB R2024a?
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 15 Oct 2025 à 0:00
Réponse apportée : MathWorks Support Team
le 21 Oct 2025 à 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?
Réponse acceptée
MathWorks Support Team
le 15 Oct 2025 à 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Axis Labels dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!