How to use plotyy for 2 different plots inside a subplot?

707 views Asked by At

I've had some problems using 'plotyy' inside a subplot.

I want a subplot with 4 figures and use in each one of them 'plotyy'. I've had some problems because of the axis' scaling, and now that I have resolved this for the first figure, but when I tried to use the same structures for the second figure from the subplot, this 2nd figure is perfect but the first one becomes a plot with only one graph instead of the previous two(so, the first 'plotyy' stops working). For a better understanding of my problem, the code that I've used is:

AXInv = subplot(2,2,1);  % Auto-fitted to the figure.
PInv = get(AXInv,'pos');    % Get the position.
delete(AXInv)
[AXInv,H1,H2] = plotyy(h,Inv,h,prod_Inv,'plot');
set(AXInv,'pos',PInv)       % Recover the position.

line([0 24],[0 1],'parent',AXInv(1),'Color',[1 1 1]) % Axis is not scaled
axis auto % Numbers on axes are crushing.
set(AXInv(1),'ytickmode','auto')  % This is new....
line([0 24],[0 1500],'parent',AXInv(2),'Color',[1 1 1]) % Axis is not scaled
axis auto % Numbers on axes are crushing.
set(AXInv(2),'ytickmode','auto')  % This is new....


AXPrim = subplot(2,2,2);  % Auto-fitted to the figure.
PPrim = get(AXPrim,'pos');    % Get the position.
delete(AXPrim)
[AXPrim,H1,H2] = plotyy(h,Prim,h,prod_Prim,'plot');
set(AXPrim,'pos',PPrim)       % Recover the position.

line([0 24],[0 1],'parent',AXPrim(1),'Color',[1 1 1]) % Axis is not scaled
axis auto % Numbers on axes are crushing.
set(AXPrim(1),'ytickmode','auto')  % This is new....
line([0 24],[0 1500],'parent',AXPrim(2),'Color',[1 1 1]) % Axis is not scaled
axis auto % Numbers on axes are crushing.
set(AXPrim(2),'ytickmode','auto')  % This is new....

Could anyone help me?

Thanks you in advance!

1

There are 1 answers

0
Franz Wurst On BEST ANSWER

I cannot tell you why your line disappears, I'm running version R2012b and it happens to me, too, so it might just be a weird bug.

But, to get around this you can delete your two delete statements because they don't serve any actual purpose here. Without these you get your proper plotyy-plot (with dummy values):

plotyy-plot with all lines

If the double ticks on the right axis bother you, you might wanna have a look at File Exchange's plt to work around this.

Piece of advice for next time: Try to include a minimal working example of your code, so that people don't have to fill variables with data by themselves. You might get an answer sooner. ;)