File Exchange

image thumbnail

Intelligent Dynamic Date Ticks

version (4.86 KB) by

Create plots with date-friendly data cursors and smart date ticks that scale with zooming & panning.

34 Ratings



View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

** Update: The archive now includes a new function setDateAxes which can be used like SET to set the properties of date axes (such as XLim) and have the tick labels update automatically. For example,
setDateAxes(gca, 'XLim', [datenum('July 1, 2008') datenum('August 1, 2008')])
** Update: DynamicDateTicks now supports an arbitrary day/month date formats. Use the third input argument to specify this: dynamicDateTicks([], [], 'dd/mm');

DYNAMICDATETICKS is a wrapper function around DATETICK which creates dynamic date tick labels for plots with dates on the X-axis. Features include:

* Smart ticks: Include year/month/day information on specific ticks as appropriate.
* Dynamic ticks: Ticks update as the plot is panned or zoomed
* Scaling ticks: Ticks change format as the timescale changes (from years to seconds).
* Support for multiple axes: Supports any combination of date and non-date axes as well as linked axes
* Date-friendly data tips: Dates displayed correctly on data cursors.


makes the current axes a date axes with dynamic properties

makes all the axes handles in vector axH dynamic date axes

dynamicDateTicks(axH, 'linked')
additionally specifies that all the axes in axH are linked. This
option should be used in conjunction with LINKAXES.

dynamicDateTicks(axH, 'link', 'dd/mm')
additionally specifies the format of all ticks that include both
date and month information. The default value is 'mm/dd' but
any valid date string format can be specified. The first two
options may be empty [] if only specifying format.

load integersignal
dates = datenum('July 1, 2008'):1/24:datenum('May 11, 2009 1:00 PM');
subplot(2,1,1), plot(dates, Signal1);
subplot(2,1,2), plot(dates, Signal4);
dynamicDateTicks([], [], 'dd/mm');

ax1 = subplot(2,1,1); plot(dates, Signal1);
ax2 = subplot(2,1,2); plot(dates, Signal4);
linkaxes([ax1 ax2], 'x');
dynamicDateTicks([ax1 ax2], 'linked')

Comments and Ratings (48)

Reinier Tromp


Ali (view profile)

Great work! I wondering if we can use this dynamic ticks to link a signal with its spectrogram?Thanks.

P.S. After zooming in and reset the original view is different in some data length than the original plots. This might lead to label overlapping especially when the label has the date-time. But i could solve the overlapping issue. Thanks again

Jesse Hopkins

Jesse Hopkins (view profile)

@DrewVam55 and @Alex B, you can add some custom code to your figure that executes when the .fig file is loaded. See 'CreateFcn' callback (Matlab version > R2014B) or 'ResizeFcn' for older versions.


@Alex B, I have been trying to come up with a way to fix this saving issue. The problem is that the zoom/pan mode objects are how the tick labels are controlled, but any modifications to these cannot be saved and carried over from each time you open the figure. The only way I found that works is if you overload your openfig function with a wrapper function that, after loading the figure, checks for "time" string pieces in the XTickLabels (for example, ':', '/', 'AM', 'PM'...) of the axis on the figure that is opened, then sets the pan and zoom objects callbacks to @updateDateLabel from Ameyas file. You could also store some sort of flag in the UserData of the figure before you save it, then just check for the status of that flag with your custom openfig function.

Steve Grobler

Really like this function, it ought to be adopted as a built-in function. Great job, thanks for making it available.

Alex B

Alex B (view profile)

This code is very useful.

Is there any way to modify this to keep the dynamic ticks after saving/reopening the figure? They seem to get turned off after save.

Pierre Quet


Niall Ryan

Amitava Guha

Great work! Very helpful.

Great Job!!!
Really helpful...


Great job, really handy!

When using the function on axes in a uipanel, the function throws an error as pointed out by Juliane and Anuraag. This can easily be fixed by ensuring that figH is a handle to the figure as suggested by Ameya, not to the uipanel. Simply use figH = get(figH, 'Parent') until you get the handle of the figure. Maybe this could be altered in the original code for future use?

Great - well done.

Javier Barro

Great job!
Thanks for thinking in 'dd/mm' format too. ;)


Shahin (view profile)

Akshay Jain

Perfect !


wonderful job!


Regarding Anuraags question: Is there any workaround to be able to use dynamic date ticks inside of a uipanel?
It would be great if anyone could help!

Ameya Deoras

Ameya Deoras (view profile)

MATLAB R2014b has built-in rotated date tick labels, as well as a datetime data type for dates. It is quite a substantial update. Check it out!

@Anuraag : you may have this error if figH is not the handle of a figure but a handle of a uipanel for example

TO verify this : type get(figH,'Style')


Nakul (view profile)


This is exactly what I was looking for. However, I am getting an error
Error in C:\Program Files\MATLAB\R2012b\toolbox\matlab\graph2d\zoom.p>zoom (line 232)

Output argument "out" (and maybe others) not assigned during
call to "C:\Program

Error in dynamicDateTicks (line 74)
z = zoom(figH);

I know it has been quite sometime since this function was posted but I would be really grateful if somebody could help

Excellent. Tried in vain to do this by simple commands - this solves dynamic zooming grid issue using datetick()!

Oleg Komarov

Oleg Komarov (view profile)

If I zoom in, then undo (CTRL+Z), the axis ticks are not updated.


roman (view profile)


Joerg (view profile)

Thanks a lot for this tool. But the code

figH = get(axH, 'Parent');

does not always lead to the parent figure. See

for one possible fix for this problem.



Bert (view profile)


Sal (view profile)

Great Tool!!!

John Petersen

Great tool.


Great function! Works perfectly and I love the linked axes option very useful when using subplot, as well as that the dates displayed correctly on data cursor.


Jirka (view profile)

Ameya Deoras

Ameya Deoras (view profile)

Jose, this function won't eliminate the dead space you see because it only modifies the ticks that would be drawn by datetick. What you need is the ability to modify the x-values in your dataset so that when they are plotted the data are no longer evenly spaced in the x-dimension. This is a much more challenging problem that this function is not set up to address.

Jose Antonio

I'm plotting data that is date/time stamped, I have data of six hour per day, 600 days, when my data is plotted, between one day and next I find a lot of dead space, It's like the hour I don't have the date were there. Do you know how can I eliminate those dead space? and use Intelligent Dynamic.


Oleg Komarov

Oleg Komarov (view profile)

I suggest to change the name to something like:


This way when I don't remember which dateticks were the "adaptive" ones I just have to write datetick and tab.

I have other datetickSOMETHING function and couldn't find immediately yours.

This is exactly what I was looking for. Great job!

Ameya Deoras

Ameya Deoras (view profile)

Hi folks! Support for setting XLim programmatically will be here shortly. Add this file to your watch list to be notified when that update is pushed through.

For PLOTYY, you can use the following syntax. Note that zooming and panning with plotyy is limited, so making fully interactive double-axes plots may be beyond the scope of this submission:

ax = plotyy(dates1, y1, dates2, y2);
dynamicDateTicks(ax, 'linked', 'mm/dd')

Dear Ameya Deoras,
Thanks for creating the very usefull program dynamicDateTick.
Though I am having two problems, as:
- I am using it on plotyy, apparently your program is not compatible with this kind of plot.
- I am using xlim.
Please if you can tell me what changes to make it would be so helpful.



Daniel (view profile)

Great tool, does exactly what it says on the box. Compatibility with XLim would be an awesome addition.

Jordan Mertes

Is there any way to make it compatible with just xlim[]. So that when i specify my x axis limits it automatically readjusts the dateticks. If so this would be really great for me. But so far I have been unable to figure it out.Any advice would be great. Just a MATLAB rookie but trying. Takk.

Shahar Barak


Judy (view profile)

I have MATLAB R14 SP1 and I got the error:

??? One or more output arguments not assigned during call to 'C:\MATLAB701\toolbox\matlab\graph2d\zoom.m (zoom)'.

Error in ==> dynamicDateTicks at 63
z = zoom(figH);

Error in ==> dynamicDateTicksTest at 4

when trying out the example in the given code. Is anyone familiar with known fixes needed for the zoom function?


Dragos Boros

The fix suggested by Thibaut works partially. When working with daily data the labels will still be reported with mm/dd format.
Trying to modify the command from line 102 by specifying a format will work but in that case the labels will only use the specified hardcoded format which will no longer vary with the data granularity

Thibaut Leroy

< Roger Parkyn: Change Line 128 and 129:
newlabels{1} = datestr(ticks(1), 'dd/mm/yy '); % Add month/day/year to first tick
newlabels(ind) = cellstr(datestr(ticks(ind), 'dd/m ')); % Add month/day to ticks where day changes

It's nearly perfect, it just needs a compatibility with "plotyy" :)

Roger Parkyn

It works faster than tlabel.m (also on the file exchange, by Carlos Adrian Vargas Aguilera). However the date formats that is uses are annoying for me as an australian: we use day then month then year, or the reverse, but NEVER month/day/year.

Hence I will be sticking with tlabel until a australian option is available.

I can't fairly give it a rating as it is probably great for americans.


Updated license


Added a function setDateAxes to set properties of an axes with dates and update tick labels automatically


DynamicDateTicks now supports an arbitrary day/month date formats. Use the third input argument to specify this: dynamicDateTicks([], [], 'dd/mm');

MATLAB Release
MATLAB 7.10 (R2010a)

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

» Watch video