How to specify which y-axis to use when adding curve to an existing plotyy
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ian
el 17 de Jul. de 2016
Comentada: Walter Roberson
el 17 de Jul. de 2016
Hi,
I have made a plotyy plot where the y-axis are different on the sides. When I hold the plot and then add another plot (an errorbar plot in my case), the new plot defaults and uses the y-axis on the left side. I need it to use the y-axis on the right side. How do I do this?
0 comentarios
Respuesta aceptada
Walter Roberson
el 17 de Jul. de 2016
ax = plotyy(.....)
axes(ax(2))
hold on
plot(....)
Or, better,
ax = plotyy(....);
hold(ax(2), 'on')
plot(ax(2), ....)
As you have notice, relying on the "current axes" to be correct does not always have the effects one wants. It is safer to always specify the axes you want to affect.
2 comentarios
Walter Roberson
el 17 de Jul. de 2016
"[AX,H1,H2] = plotyy(_) returns the handles of the two axes created in AX and the handles of the graphics objects from each plot in H1 and H2. AX(1) is the left axes and AX(2) is the right axes."
After that the step would have been to notice that it did not say which of the two axes will become the "current" axes, which could then have led you to question which will be the "current" axes and to question whether you can be sure that it is going to be consistent about which axes it leaves as the "current" axes, considering that it does not document it. From there the Defensive Programming strategy would be to assume that it might not always be consistent and that even if it is now that it might change in future, and so leading you to code explicit axes selection after the plotyy() call.
On the other hand, the lesson of always using explicit parenting even within one routine comes from "the school of hard knocks". Timer interrupts can occur between any two lines, and increasingly more, some kinds of graphics interrupts can occur while other graphics interrupts are executing. And also, if you start debugging a program that does graphics, then if you ever click on an object to move it so you can see a different window (such as the command window or the edit window) then that can change which window has focus and so change the current object. The safest strategy is to assume that the current axes might change at any time.
Más respuestas (0)
Ver también
Categorías
Más información sobre Two y-axis 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!