Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

 Messages: [ Previous | Next ]
 dpb Posts: 9,850 Registered: 6/7/07
Re: Plotyy squeezed second x axis
Posted: Feb 21, 2014 9:53 AM

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

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.

--

Date Subject Author
2/21/14 Sancuks
2/21/14 dpb