File Exchange Pick of the Week

Our best user submissions

Dynamic Date Ticks 5

Posted by Jiro Doke,

Jiro's pick this week is Dynamic Date Ticks by our fellow MathWorker (and an Application Engineer) Ameya. If you work with time series data, this is a must-have utility.

Have you ever wanted to plot a graph with dates along the x-axis? MATLAB has had a function called datetick for a long time, and it gives you a nice set of tick labels with date strings. But often times, you may want to interact with your plot by zooming and panning. Since datetick fixes the tick labels at the time of creation, the labels may disappear if you zoom in too far or pan away from the original limits. There are techniques you can employ to automatically update the tick labels after zooming and panning, or you can use Ameya's dynamicDateTicks.

Actually, there are a few entries on the File Exchange that provide automatic update of dateticks, one of which was selected as a Pick of the Week. Most of them leverage the callback behaviors of zoom and pan. What's unique about Ameya's function is that not only does it dynamically update the tick labels as you zoom and pan, it also shows year or day changes (so you always have the full date information), and displays data tips appropriately.

Comments

Give this a try and tell us what you think, or leave a comment for Ameya on the submission page.


Get the MATLAB code

Published with MATLAB® 7.10

Note

Comments are closed.

5 CommentsOldest to Newest

Michael Robbins replied on : 1 of 5
Good choice. We need more date functionality in MATLAB. A transparent date class is truly the way to go.
Marcelo replied on : 2 of 5
I have been using tlabel. It's very flexible about different formats and also changes the marks as you zoom or pan.
Bob replied on : 4 of 5
Michael, what do you mean by "transparent date class?" How would you use it, ideally? :) Thanks Bob
Divya replied on : 5 of 5
Could someone provide me an example of how to plot the date-time axis in dd-mm-yyyy HH:MM:SS in MATLAB. I have tried datetick but got only one value in the X axis displayed. I am reading the raw data from a txt file like the one shown below and would like to plot the date time. DATE TIME Temperature 3-12-2010 12:00:00 16.303223 3-12-2010 12:00:05 16.63046875 3-12-2010 12:00:12 16.63046875 3-12-2010 12:00:22 16.303223 3-12-2010 12:00:45 16.63046875 3-12-2010 12:01:03 16.63046875 Thanks, Diana