COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Dateticks compatible with plotyy ans xlim

• Email
• Follow

```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.
```
 0

See related articles to this posting

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

```
 0

```
"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
http://www.mathworks.com

```
 0

```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.
```
 0

```"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));
```
 0

```HI Kelly,
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!
```
 0

```
"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
http://www.mathworks.com

```
 0

```"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <iis0o8\$kq9\$1@fred.mathworks.com>...
> HI Kelly,
> 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.
```
 0

7 Replies
551 Views

Similar Articles

12/5/2013 7:17:15 PM
page loaded in 51316 ms. (0)