How to plot two plotyy plots in the same plot?

Illustration
angelinawilliams97 - 2020-03-16T10:49:37+00:00
Question: How to plot two plotyy plots in the same plot?

I am trying to plot four plots in the same figure. First i plot using plotyy. Then two graphs are created, each with a y-axis. Now I want to plot another two plots. One using y-axis-1 and one using y-axis-2. How do i do this? If I do   [ax,h1,h2] = plotyy(...) hold on plot(ax(1),...) plot(ax(2),...) i don't get all four plots.

Expert Answer

Profile picture of Neeta Dsouza Neeta Dsouza answered . 2025-11-20

[ax,h1,h2] = plotyy(...) 
hold(ax(1))
plot(ax(1),...)
hold(ax(2))
plot(ax(2),...)

The problem was simple, hold on just holds the current axes and your plotyy makes two axes so only one is the current.


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!