Code covered by the BSD License  

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

4.8 | 6 ratings Rate this file 58 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)

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 (7)
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

Christian (view profile)

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