Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Plotyy squeezed second x axis
Replies: 1   Last Post: Feb 21, 2014 9:53 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dpb

Posts: 7,871
Registered: 6/7/07
Re: Plotyy squeezed second x axis
Posted: Feb 21, 2014 9:53 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 2/21/2014 7:54 AM, Sancuks wrote:
> Hi, I am trying to plot 3 lines on the left yaxis and one on the right
> yaxis using plotyy.
> Here is my current code:
> hold on;
> [ax hl hr] = plotyy(1:N,xPrtclT(1,:),1:N,c);
> set(hl,'Color','r','LineStyle','-','LineWidth',3);
> set(hr,'Color','k','LineStyle','none','Marker','*'); get(ax(1));
> plot(ax(1),1:N,xPrtclT(2,:),'b');
> plot(ax(1),1:N,xPrtclT(3,:),'g');
> hold off;
>
> This does everything I want, but it overlays the second axis so that the
> x axis of the second plot takes only 1/3 of the space of the first plot.
> Does that make sense? The same happened if I used set(ax(1),ylim,[])!!!
> I also tried using hold(ax(1),'on'), but this returns error that 'fig'
> is unknown in the code of plotyy.


If you change or do something that automagically changes the limits of
one of the two x-axes in plotyy() you must make the same change on the
other. W/O an actual runnable example it's hard to see precisely what
is the issue with your code but a couple of comments...

Why 'hold on' _before_ the plotyy? Seem like that should be the
beginning clean position. Then set it after to add the other lines.
But, it doesn't seem like there's any reason you couldn't have just
passed the array in the plotyy call--the colors will auto-cycle and if
you want them in a specific order you can set that manually as well more
succinctly than the extra plot() calls.

--




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.