File Exchange

image thumbnail

Datetickzoom - automatically update dateticks

version 1.0 (2.48 KB) by

Label axis with date ticks that automatically update when zooming or panning



No License

DATETICKZOOM behaves completely identical to DATETICK, except that tick labels are automatically updated when zooming or panning.

Comments and Ratings (26)


How can I switch this zoom function off? When I use it in a GUI axes, after cla reset and plotting another graph without a date axis, zooming still converts the axis to dates.

Stefan Weber

Very good function!
Is there a possibility to keep always 5 dateticks (static, at the same position) on the x-axis of the plot?
I have enough data points to guarantee that there is (almost) always a date for each of the five dateticks.
Thanks in advance!

Lovely function, but I do have an additional feature request Is it possible to extend this function to cover multiple subplots so that when I zoom on one, the tick marks and labels for all the plots linked together by linkaxes are updated? Many thanks.

Felix Terhag

Gaurav Soni

Wow, this is a great tool. I had been wanting this for so long.

This is a great script overall. But I have one question:

Is it possible to easily add more ticks? For example, I have a time series from March 1 to March 17. When I plot the full time series it only gives two ticks (one at March 5 and one at March 12). Is there a way to force it to always have some number of ticks on the x-axis? For example, no matter what zoom level, I would like to have at least 10 ticks on the x-axis. Currently, no matter what zoom level, the maximum number of ticks I get is 3.

Any help is appreciated.

Zhou Mr

Very very very useful! That's it!!!!

Amitava Guha

Works like a charm. Very useful.


Kristin Busa

Following up on latheefth's comment -- is there a way to include milliseconds in this function? Sub-seconds, there are no longer any ticks or tick labels shown. Thank you!


Amedeo (view profile)


Davide (view profile)


Thank you!


I agree on F Moisy comment from 2007. How do I use this witouth having to lose the date info when going down to hours and minutes?



I need to zoom it to milli sec, but it happens only till second.
Is there any way of doing it?


hold arrowkey -> matlab crashes


Karen (view profile)


adam (view profile)


Hi Christophe,
I'm getting the error "One or more output arguments not assigned during call" in line 39 when using datetickzoom('x'). Any clue what I'm doing wrong?

Carlos Adrián Vargas Aguilera

Excellent job! Congratulations Christophe! I made a modification of your function and MATLAB's to put what is left by the ticks on the date-axis.

Rajesh: if time is in X-axis you can use
a = linkprop(h, {'XTick', 'XTickLabel', 'XLim', 'YLim'});
where h are your axes handles. And to link the label too:
b = linkprop(cell2mat(get(h,'XLabel')), 'String');


Rajesh Rajaram

It is a very nice option to add to matlab. It works great on a single plot.

However I am not sure how I could use it when I also need to use the linkaxes option to link multiple subplots.

Dan Kominsky

Very nice. This has been an annoying aspect of MatLab for some time. Thank you.

Christophe Lauwerys

Concerning your remark: the switching between different dateforms is desired behavior since, in my opinion, the resolution of the ticks should increase when zooming in.

F Moisy

Very useful, thanks!

One remark: it seems that datetickzoom uses the input argument dateform=0 by default, even if a second input argument is given. For instance, datetickzoom('x',1) should display labels in the form 'dd-mmm-yyyy' whatever the zoom. Instead, it automatically switches between different dateforms when zooming.

MATLAB Release
MATLAB 7.3 (R2006b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today