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:
Dateticks compatible with plotyy ans xlim

Subject: Dateticks compatible with plotyy ans xlim

From: Camille Couzi

Date: 8 Feb, 2011 14:12:03

Message: 1 of 8

Hi matlabers!

I am working with a plotyy, ploting matrix with dates in x axis and values on y axis.
My two matrix have not the same time values, that's why I use plotyy and I readjust the x axis with xlim property.

My dates are in datenum format for the moment, but I would like to see dateticks with a format 'dd-mmm-yyyy HH:MM:SS'.

I have been trying tlabel, datetick, dateNtick, dynamicDateTicks and apparently all these function have compatibility with plotyy and xlim...


Anybody have an idea about how to solve this problem?
Any idea will be very usefull, thanks in advance!!!

Camille.

Subject: Dateticks compatible with plotyy ans xlim

From: Camille Couzi

Date: 8 Feb, 2011 14:20:05

Message: 2 of 8

Sorry little mistake: "I have been trying tlabel, datetick, dateNtick, dynamicDateTicks and apparently all these function have compatibility PROBLEMS with plotyy and xlim..."

Thanks for your help...

Subject: Dateticks compatible with plotyy ans xlim

From: Steven_Lord

Date: 8 Feb, 2011 14:23:59

Message: 3 of 8



"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message
news:iirivj$fam$1@fred.mathworks.com...
> Hi matlabers!
>
> I am working with a plotyy, ploting matrix with dates in x axis and values
> on y axis.
> My two matrix have not the same time values, that's why I use plotyy and I
> readjust the x axis with xlim property.
>
> My dates are in datenum format for the moment, but I would like to see
> dateticks with a format 'dd-mmm-yyyy HH:MM:SS'.
>
> I have been trying tlabel, datetick, dateNtick, dynamicDateTicks and
> apparently all these function have compatibility with plotyy and xlim...

figure
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
[AX,H1,H2] = plotyy(x+now,y1,x+now,y2,'plot');
datetick(AX(1), 'x', 'mm/dd', 'keepticks', 'keeplimits')
datetick(AX(2), 'x', 'mm/dd', 'keepticks', 'keeplimits')

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Dateticks compatible with plotyy ans xlim

From: Camille Couzi

Date: 8 Feb, 2011 14:50:04

Message: 4 of 8

Thanks Steven.
That works but I need the tick to re-adjust when zooming and panning.
With your code, I got 4ticks but when I zoom in on a piece of figure the ticks don't re-draw...
(that's why I was trying using dynamic date ticks...)
any other idea?
Thanks a lot for your help.

Camille.

Subject: Dateticks compatible with plotyy ans xlim

From: Kelly Kearney

Date: 8 Feb, 2011 15:24:04

Message: 5 of 8

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <iirl6s$c98$1@fred.mathworks.com>...
> Thanks Steven.
> That works but I need the tick to re-adjust when zooming and panning.
> With your code, I got 4ticks but when I zoom in on a piece of figure the ticks don't re-draw...
> (that's why I was trying using dynamic date ticks...)
> any other idea?
> Thanks a lot for your help.
>
> Camille.

You mentioned you tried tlabel, but not what the problem was. Using Steve's example with tlabel instead of datetick should allow you to zoom and pan with tick updates. If you want to reset the x-limits, you can do that before calling tlabel:

figure
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
[AX,H1,H2] = plotyy(x+now,y1,x+now,y2,'plot');
% set(AX, 'xlim', [a b])
tlabel(AX, 'whichaxes', AX(1));

Subject: Dateticks compatible with plotyy ans xlim

From: Camille Couzi

Date: 8 Feb, 2011 18:07:04

Message: 6 of 8

HI Kelly,
Thanks for reply.
Sorry if I was not enough precise.
tlabel is not working fine for me because it displays ok the tick labels at the beginning, but when I zoom in, out, and I pan, the ticks are not re-drawing. so it is like if I was using datetick.
perhaps it is a problem with the double x ticks, as I have the xticks of AX(1) and the xticks of AX(2):

% turn off 2nd axes tick marks
setAX(2),'XTick',[])
set(AX(2),'XTickLabel',[])

??
Any idea?!!!!!!

Thanks again for helping me with this very little but very annoying problem.
Camille!

Subject: Dateticks compatible with plotyy ans xlim

From: Steven_Lord

Date: 8 Feb, 2011 18:50:23

Message: 7 of 8



"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message
news:iirl6s$c98$1@fred.mathworks.com...
> Thanks Steven.
> That works but I need the tick to re-adjust when zooming and panning.

Then set the ActionPostCallback on your zoom or pan mode objects to call
DATETICK to update the tick labels.

http://www.mathworks.com/support/solutions/en/data/1-9Q79XN/?solution=1-9Q79XN

http://www.mathworks.com/help/techdoc/ref/zoom.html
http://www.mathworks.com/help/techdoc/ref/pan.html

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Dateticks compatible with plotyy ans xlim

From: Kelly Kearney

Date: 8 Feb, 2011 19:55:04

Message: 8 of 8

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <iis0o8$kq9$1@fred.mathworks.com>...
> HI Kelly,
> Thanks for reply.
> Sorry if I was not enough precise.
> tlabel is not working fine for me because it displays ok the tick labels at the beginning, but when I zoom in, out, and I pan, the ticks are not re-drawing. so it is like if I was using datetick.
> perhaps it is a problem with the double x ticks, as I have the xticks of AX(1) and the xticks of AX(2):
>
> % turn off 2nd axes tick marks
> setAX(2),'XTick',[])
> set(AX(2),'XTickLabel',[])
>
> ??
> Any idea?!!!!!!
>
> Thanks again for helping me with this very little but very annoying problem.
> Camille!

Why do you need to turn off ticks on the second axis? The tlabel function automatically links the two axes (if issued as I demonstrated above), so if you delete those ticks after issuing tlabel, you actually delete ticks from both axes. The advantage of tlabel's linking is that you don't need to worry about keeping the x-properties of the two axes in sync. When you run the simple example I gave above, do the ticks update when you zoom and pan? They should.

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