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

Thread Subject:
plotyy with datetick out of sync

Subject: plotyy with datetick out of sync

From: cabrego

Date: 16 Dec, 2013 22:55:07

Message: 1 of 4

Greetings,

This code produces desired outcome..a plotyy with x axis time stamps (e.g., '12-Nov-2013 13:00:00').

H=datenum(Hd);

[AX,H1,H2]=plotyy(H,[Asumfiltered/mean(Asumfiltered);],H,[Atemp ],'plot');
datetick('x',13)
set(AX(2),'XTick',[])


This code almost works...it is identical code but only using a portion of the array (e.g., 3:16). The problem is they X axis are out of sync, if I comment out datetick the plot is synced but the serial number on the x-axis is not converted to the date via date tick (obviously a problem).

[AX,H1,H2]=plotyy(H(3:16),[Asumfiltered(3:16)/mean(Asumfiltered(3:16));],H(3:16),[Atemp(3:16)],'plot');
datetick(AX(1),'x',13)
set(AX(2),'XTick',[])

Subject: plotyy with datetick out of sync

From: dpb

Date: 16 Dec, 2013 23:23:52

Message: 2 of 4

On 12/16/2013 4:55 PM, cabrego wrote:
> Greetings,
>
> This code produces desired outcome..a plotyy with x axis time stamps
> (e.g., '12-Nov-2013 13:00:00').
>
> H=datenum(Hd);
>
> [AX,H1,H2]=plotyy(H,Asumfiltered/mean(Asumfiltered),H,Atemp,'plot');
> datetick('x',13)
> set(AX(2),'XTick',[])
>
>
> This code almost works...it is identical code but only using a portion
> of the array (e.g., 3:16). The problem is they X axis are out of sync,
> if I comment out datetick the plot is synced but the serial number on
> the x-axis is not converted to the date via date tick (obviously a
> problem).
>
> [AX,H1,H2]=plotyy(H(3:16),[Asumfiltered(3:16)/mean(Asumfiltered(3:16));],H(3:16),[Atemp(3:16)],'plot');
>
> datetick(AX(1),'x',13)
> set(AX(2),'XTick',[])

Use datetick() on both axes to keep them consistent should solve the
issue. In general should do it on plotyy x-axes as a general rule.

datetick(AX,'x',13)

--

Subject: plotyy with datetick out of sync

From: cabrego

Date: 17 Dec, 2013 16:01:07

Message: 3 of 4

dpb <none@non.net> wrote in message <l8o22o$j35$1@speranza.aioe.org>...
> On 12/16/2013 4:55 PM, cabrego wrote:
> > Greetings,
> >
> > This code produces desired outcome..a plotyy with x axis time stamps
> > (e.g., '12-Nov-2013 13:00:00').
> >
> > H=datenum(Hd);
> >
> > [AX,H1,H2]=plotyy(H,Asumfiltered/mean(Asumfiltered),H,Atemp,'plot');
> > datetick('x',13)
> > set(AX(2),'XTick',[])
> >
> >
> > This code almost works...it is identical code but only using a portion
> > of the array (e.g., 3:16). The problem is they X axis are out of sync,
> > if I comment out datetick the plot is synced but the serial number on
> > the x-axis is not converted to the date via date tick (obviously a
> > problem).
> >
> > [AX,H1,H2]=plotyy(H(3:16),[Asumfiltered(3:16)/mean(Asumfiltered(3:16));],H(3:16),[Atemp(3:16)],'plot');
> >
> > datetick(AX(1),'x',13)
> > set(AX(2),'XTick',[])
>
> Use datetick() on both axes to keep them consistent should solve the
> issue. In general should do it on plotyy x-axes as a general rule.
>
> datetick(AX,'x',13)
>
> --
>
>
>
Thanks, that worked!

Subject: plotyy with datetick out of sync

From: dpb

Date: 17 Dec, 2013 21:07:45

Message: 4 of 4

On 12/17/2013 10:01 AM, cabrego wrote:
> dpb <none@non.net> wrote in message <l8o22o$j35$1@speranza.aioe.org>...
...

>> Use datetick() on both axes to keep them consistent should solve the
>> issue. In general should do it on plotyy x-axes as a general rule.
>>
>> datetick(AX,'x',13)
>>
>>
> Thanks, that worked!

Yes, the general lesson is to _always_ do the same thing to both x axes
with plotyy(). Otherwise you will have the two that aren't in cahoots
with each other. I've not investigated thoroughly whether linking
solves the problem cleanly but using the axes handle vector generally
does for everything that has the facility to handle the vector input of
handles.

Only in a few very rare instances can I think of any reason you wouldn't
want to do the same thing to both routinely.

--

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us