MATLAB: How to specify which y-axis to use when adding curve to an existing plotyy

plotyyy axis

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?

Best Answer

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.