Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

How to plot two plotyy plots in the same plot

Asked by Benjamin

Benjamin (view profile)

on 15 Aug 2011
Latest activity Commented on by Paulo Fagandini

Paulo Fagandini (view profile)

on 27 Sep 2014

I am trying to plot four plots in the same figure. First i plot using plotyy. Then two graphs are created, each with a yaxis.

Now I want to plot another two plots. One using yaxis-1 and one using yaxis-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.

Thanks :)

Ben

1 Comment

Benjamin

Benjamin (view profile)

on 15 Aug 2011

I mean:
[ax,h1,h2] = plotyy(...)
hold on
plot(ax(1),...)
plot(ax(2),...)

Benjamin

Benjamin (view profile)

Products

No products are associated with this question.

2 Answers

Answer by Paulo Silva

Paulo Silva (view profile)

on 15 Aug 2011
Accepted answer
[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.

1 Comment

Benjamin

Benjamin (view profile)

on 15 Aug 2011

Phenomenal, thanks!:)

Paulo Silva

Paulo Silva (view profile)

Answer by the cyclist

the cyclist (view profile)

on 15 Aug 2011
figure
[hax12 line1 hline2] = plotyy(1:10,1:10,1:10,2:11)
set(hax12,'NextPlot','add')
plot(hax12(1),1:10,3:12)
plot(hax12(2),1:10,4:13)

3 Comments

Benjamin

Benjamin (view profile)

on 15 Aug 2011

Great, thanks a lot! :)

Manimaran Kanesan on 18 Jun 2013

Thank you....

Paulo Fagandini

Paulo Fagandini (view profile)

on 27 Sep 2014

Thanks, this saved me a second day of trials!

the cyclist

the cyclist (view profile)

Contact us