View License

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

» Watch video

Highlights from
ticklabelformat - set a dynamic format of axes tick labels

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

4.7 | 9 ratings Rate this file 24 Downloads (last 30 days) File Size: 5.4 KB File ID: #36254 Version: 1.5
image thumbnail

ticklabelformat - set a dynamic format of axes tick labels


Yair Altman (view profile)


18 Apr 2012 (Updated )

ticklabelformat sets the axes tick labels format. The format is preserved during zoom/pan/maximize

| Watch this File

File Information

ticklabelformat sets the format of an axes tick labels based on sprintf format specifiers. The format is preserved during zoom/pan/maximize and applied to the dynamic tick values.
Calling ticklabelformat with an empty ([] or '') format will revert to Matlab's normal tick labels display behavior.
     ticklabelformat(hAxes, axName, format)
Input Parameters:
     hAxes - handle to the modified axes, such as returned by the gca function
     axName - name(s) of axles to modify: 'x','y','z' or combination (e.g. 'xy')
     format - format of the tick labels in sprintf format (e.g. '%.1f V') or a
                 function handle that will be called whenever labels need to be updated
     ticklabelformat(gca,'y','%.6g V') - sets y axis in current axes to display 6 significant digits
     ticklabelformat(gca,'xy','%.2f') - sets x & y axes in current axes to display 2 decimal digits
     ticklabelformat(gca,'z',@myFcn) - sets a function to update the Z tick labels in current axes
     ticklabelformat(gca,'z',{@myFcn,extraData}) - sets an update function as above, with extra data
     This code heavily relies on undocumented and unsupported Matlab functionality. It works on Matlab 7+, but use at your own risk!
Technical description and more details:
Bugs and suggestions:
     Please send to Yair Altman (altmany at gmail dot com)


This file inspired Offset Ticks.

MATLAB release MATLAB 7.14 (R2012a)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (11)
12 Aug 2016 Erica Coenen

Great script!
Could you please post an example of an update function: myFcn? That would be really helpful.

Comment only
28 Jan 2016 Gian Mario Manca

Very nice. A minor issue that I want to report. If you save the figure as a matlab figure and you reload it, it will generate an error.
The figure will open and it will have the formatted labels but they will not auto-update anymore. You will have to manually rerun the ticklabelformat command. Matlab 2015b.

28 Jan 2016 Gian Mario Manca

tested with 2015b

06 Aug 2015 Krisztian Szucher  
28 Jun 2015 Chang hsiung

great, thanks a lot.

28 Jun 2015 Yair Altman

Yair Altman (view profile)

@Chang - set(gca,'FontSize',20)

Comment only
28 Jun 2015 Chang hsiung

can you change the font size ?
somehow in my Matlab 2014b version, I can not change the font size of ticklabels anymore ?

26 Jun 2015 Robert

Robert (view profile)

This is a great function! I especially like the function handle formatting option.

I noticed that the code for R2014b and newer (HG2) needed a few tweaks to:

1) work when format was a function handle (when the labels are updated for the first time, the code assumes format is a string for sprint) and

2) to delete prior listeners when format is empty (I think the hRuler listener sticks around even when the hAxes one is removed).

11 Feb 2015 Christian

Great script. Callback functionality for formatting is also very useful.

11 Jul 2013 Jorge Arcila Zea

Excellent script. It was very useful. Thank you for share it

17 May 2012 Mayi

Mayi (view profile)

Very good, I have use it in my application. Tanks

20 Apr 2012 1.1

Clarified summary & description

02 Oct 2014 1.3

updated for R2014b (HG2)

05 Jan 2015 1.4

fix for R2014b (HG2)

27 Jun 2015 1.5

fixes suggested by user Robert for R2014b (HG2)

Contact us