Code covered by the BSD License  

Highlights from
tlabel.m v2.6.1 (Sep 2009)


4.9 | 10 ratings Rate this file 33 Downloads (last 30 days) File Size: 12.2 KB File ID: #19314
image thumbnail

tlabel.m v2.6.1 (Sep 2009)



24 Mar 2008 (Updated )

Same as DATETICK but with ZOOM, PAN, LINKAXES and more!

| Watch this File

File Information

This program places dates on time axis as DATETICK and works with ZOOM and PAN as DATETICKZOOM by Christophe Lauwerys. But, it also shows the full date after zooming or panning by using the ticks and time-axis label. So, if you zoom in down to second, you won't loose "when" you are.

The input arguments are equal to those of DATETICK function, but if more than one axis handle is specified, they all will be LINKED!

Also, some other options are available, for example, the use of LOCAL LANGUAGE for the months (default), or the use of an specific date format: 'DD HH:MM SS.FFF' for example.

Besides, sometimes with DATETICK you don't get optimal results. This program (try to) fix this problem.

Just use it after some plot function with days (see DATENUM) in one of his axis (time-axis):

t = linspace(0,1) + now;
x = rand(size(t));
axis tight
tlabel % <----

Enjoy it!
Bugs reports and suggestions will be very appreciated!


Datetickzoom Automatically Update Dateticks inspired this file.

This file inspired Bar And Candle Style Graph For Stocks, Linkzoom.M V1.3 (Aug 2009), Addaxes.M V1.1 (Sep 2009), Quiver2.M V1.2 (Nov 2009), and Xunits, Yunits And Zunits.M (Jul 2014).

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (17)
05 Dec 2013 Rowan Fox

I've used tlabel for a long time in matlab, but now I'm learning python/matplotlib, I'm quite sad that there's no equivalent of tlabel! Great work, Carlos.

14 Dec 2011 Patrick

Hi Carlos,
I have a problem with non working tlabel when opening a saved figure (.fig): the dateticks are not changing when I zoom.
I tried to load before tlabel in the matlab path but it did not helped.
Did you heard of the problem ?

All the best,


11 Jun 2011 Nicolas

hold arrowkey -> Matlab crashes!
solved it by adding:
persistent running
if isempty(running)
running = 0;
if running==0
running = 1;
to the top of the tlabel function (line 198),
running = 0;
to the bottom of the tlabel function (line 303)
thanks for this great submission!
from what i've seen the datetick tool with greatest functionality.
this functionality however is payed by a slow callback.

27 Jan 2011 Camille Couzi

Hi Carlos,
Thanks for your file.
I am trying to use it with a plotyy. I have seen that you posted a new version on29/8/2009 for a bug with plotyy.
However, I have a problem: tlabel displays ok the ticks, but when I zoom in and out, the datetick don't refresh. What can I do?
This is what I wrote:

[AX,H1,H2] = plotyy(v1(:,1),v1(:,2),v2(:,1),v2(:,num_col));

set(AX(1),'XLim',([min(v2(:,1)) max(v2(:,1))]))
set(AX(1),'YLim',([min(v1(:,2))-0.5 max(v1(:,2))+0.5]))

set(AX(2),'XLim',([min(v2(:,1)) max(v2(:,1))]))

% set(AX(2),'XTick',[])

tlabel(AX, 'x', 0, 'keepticks')
tlabel(AX(2), 'x', 0, 'keepticks')

Thanks for your help!

13 Oct 2010 Christian W├Ârner  
11 Oct 2009 Willem

My mistake or Mathworks mistake for not stating so in the help file. On a Mac you need to use the option key, not shift for zooming out. Works great now!

06 Oct 2009 Carlos Adrian Vargas Aguilera

Hi Stefan, as far as I know, that functionality of the ZOOM and PAN functions does not work even on the first version of MATLAB v7.

One workaround is to edit "temporarly" the ZOOM/PAN function by adding the line
at the end.

Or make your one function

function myzoom()

and run
>> datetick
>> myzoom

Let me know if it works for you. Via email if possible.


06 Oct 2009 Stefan Achleitner

tlabel.m v2.6.1 (Sep 2009)

Dear Carlos

I tried to use tlabel within a Matlab 2006a Version?
I got the following error(see below).
Is you tool compatible with older matlab versions than the 2008a stated ?

If not, do you have any suggestions on similar alternatives to datetick that run under 2006a?

Thanks Stefan

??? Output argument "out" (and maybe others) not assigned during call to "D:\Programme\MATLAB\R2006a\toolbox\matlab\graph2d\zoom.m (zoom)".

Error in ==> zoom at 80
if nargin==2 && ...

Error in ==> tlabel at 242
zh = zoom(xa);

31 Aug 2009 Raghu

I m not able to make check this out, i did follow all the steps mentioned but im getting one error:

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

Error in ==> tlabel at 237
zh = zoom(xa);

What do i need to do for this ?
Please let me know,

28 Aug 2009 Scott Otterson

This does a great job of solving a constant Matlab plot annoyance. They really ought to pay you for it!

23 Aug 2009 Roger Parkyn

Worked well with the tests I ran. It seems to use good date formats when used in the default mode (i.e. just typing "tlabel;") so I will be using it in preference to "datetick;".

21 Aug 2009 Kelly Kearney

I've been using an older version of this function for a few months now, and it's a great little utility, much more flexible than datetick. However, I noticed two small bugs with this release:

1) If you plot data that spans several years, then zoom in to a few-months range, a reference year will appear in the ylabel. However, when you revert to the original multi-year range, the reference year ylabel remains.

2) If datetick thinks there should only be one tick, the new version of tlabel will crash on tlabel>fixTicks line 1108. This is really due to buggy tick location calculations in datetick, and may only occur in older versions of Matlab (I'm running R2007a) since I believe datetick has been updated since then. This situation only seems to arise for a small subset of cases where data spans a year plus a few hours. Older versions of tlabel were able to handle this case.

Other than those two issues, great function, and I really like the new 'whichAxes' and 'reference' options.

21 Aug 2009 Carlos Adrian Vargas Aguilera

Bugs fixed on v2.4 Roger! Carlos

21 Aug 2009 Roger Parkyn

This looks very useful as I have been a bit frustrated with datetick not zooming so . I may be having trouble understanding the help though, as my testing of it didn't go very well (see script below, with comments). In particular:
1) tlabel; on its own didn't do much.
2) I couldn't feed it a numeric date format (e.g. 20) even thoughh the help says I can.

Any help with this would be appreciated as I will find this very useful.

Thank you

Roger Parkyn

sd = 734010:1:735000; %Test data vector
ydata = sin((sd - 734500)/73.4500); %Test data
figure; plot(sd, ydata);
datetick; %works ok but won't zoom
tlabel; %Doesn't give a sensible date format; just puts the serial date on
tlabel('ddmmmyy HH:MM');
tlabel(20); %Does not work; script fails

17 Feb 2009 Thomas

Zoom-functionality makes it so much better than the built-in datetick! Thanks.

16 Jul 2008 Carlos Adrian Vargas Aguilera

Yes, it can be done, Vincent. Let me work about it.


15 Jul 2008 Vincent Holton

This has been very useful to me. Carlos, is there any way to put labels in just one of the linked axes?

08 Jun 2009

V2.0 Rewritten code. Mayor changes with inputs and link axes. No more outputs allowed.

30 Jun 2009

v2.1: 'keepticks' and 'keeplimits' default's changed accordin to ticks and limits auto/manual mode.

03 Jul 2009

v2.1.1 Fixed small bug on new 'keep's functionality thanks to Ayal Anis!

14 Jul 2009

v2.1.2 Fixed another small bug almost in the same place as the last one.

29 Jul 2009

v2.2 Finally fixed BUG with 'keep's options. Fixed small bug with temporal figure creation. New 'none' option for 'Reference'. Fixed small BUG with Double-Click. Other minor changes.

20 Aug 2009

v2.3 Fixed bug with PLOTYY. Fixed bugs on parse inputs and now the 'reference' option moves the axes label to the specified point as suggested by Giles Lesser.

20 Aug 2009

Fixed small typo on help (version and date)

21 Aug 2009

v2.4 Fixed BUG when displaying years. Fixed BUG with numeric format (thanks to Roger Parkyn!). Added 'freeticks' and 'freelimits' options.

21 Aug 2009

v2.5 Fixed bug with label date and unique tick (thanks to Kelly Kearney!)

07 Sep 2009

v2.6 Fixed bugs with very few ticks. Thanks to Mary-Louise Timmermans.

30 Sep 2009

v2.6.1 Fixed small bug with 'middle' reference option, thanks to Ayal Anis.

Contact us