Can the same axis scaling be obtained for the left and right y axes using "yyaxis" in MATLAB R2024a?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 15 de Oct. de 2025 a las 0:00
Respondida: MathWorks Support Team
el 21 de Oct. de 2025 a las 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?
Respuesta aceptada
MathWorks Support Team
el 15 de Oct. de 2025 a las 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Axis Labels en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!