File Exchange

image thumbnail

Datetickzoom - automatically update dateticks

version (1009 Bytes) by Christophe Lauwerys
Label axis with date ticks that automatically update when zooming or panning


Updated 21 May 2007

No License

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

Cite As

Christophe Lauwerys (2021). Datetickzoom - automatically update dateticks (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (35)


Trop fort, merci de la part de la 7e Compagnie de SeaTech Toulon (France)

Chaokang Liao

That is something Mathworks should add as one of the important plot function. Much Appreciate!

Tor Aarskog

Hello. while the function itself works perfectly. Although, when saving the figure and opening it on a later occasion, the datetick zoom function does not work. Any suggestions to solve the problem?

grid on
xlabel('Date []'); ylabel('Acceleration [m/s^2]');
title('Acceleration time history - Superstructure - Bridge')
pbaspect([2 1 1])
h = gca;
h.XTickLabelRotation = 45; %45 = angle of axis label
axis tight
plot1 = fullfile(plot_folder_directory,'Acceleration time history - Superstructure - Bridge');

Lloyd Bumm

mohammad ibrahim

Hello munsense
have you an answer fro your question:
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

I have the same issue

thank you


Helpfull function. I use this function in a figure with two subplots created from the app designer. I found two probems:
# zoom in one subplot doesn't change the dateticks in the other subplot according to the zoomed one
# if you hit the "Restore" button of the plot the ticks get squeezed togethere


Here is a basic alternative using a listener:

function datetick2(axis_handle,tick_axis,varargin)
%Auto update dateticks after zoom/pan, ex: datetick2(gca,'x')

Patrik Eschle



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!

Brian Scannell

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.


Gaurav Soni

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

Darcy Cordell

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.

Israel Begashaw

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!




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


Marc Listmangof



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 Compatibility
Created with R2006b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!