Can the same axis scaling be obtained for the left and right y axes using "yyaxis" in MATLAB R2024a?
6 views (last 30 days)
Show older comments
MathWorks Support Team
on 15 Oct 2025 at 0:00
Answered: MathWorks Support Team
on 21 Oct 2025 at 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?
Accepted Answer
MathWorks Support Team
on 15 Oct 2025 at 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 Comments
More Answers (0)
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!