No License

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

» Watch video

Highlights from
Format Tick Labels

4.7 | 35 ratings Rate this file 63 Downloads (last 30 days) File Size: 17.5 KB File ID: #15986 Version: 1.0
image thumbnail

Format Tick Labels


Alexander Hayes (view profile)


19 Aug 2007 (Updated )

Replace Tick Label with Specified Formattable Objects.

Editor's Notes:

This was a File Exchange Pick of the Week

| Watch this File

File Information

Will replace axes tick labels with formatted text objects that can include both Tex and LaTex interpreted strings. Primary example is to add degree symbols to labels. Inputs can be a cell array of strings or a single string to be appended to the end of each of the current labels. Header documentation includes several examples. Labels can also be rotated.


This file inspired Simulate Control Of Magnetized Tetrahymena Pyriformis Cells, Format Tick Labels (Extended V2), Tick2text: Create Easy To Customize Tick Labels, and Format Tick Labels (Extended).

MATLAB release MATLAB 7.3 (R2006b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (46)
23 Jul 2016 Jen-Hao Cheng

20 Apr 2016 Jannis Reich

20 Apr 2016 Jannis Reich

02 Dec 2015 Lala

Lala (view profile)

Very useful; couldn't understand what 'offset' is or get it to work, otherwise this really helped and very easy to use.

21 Jul 2015 emmanouil protonotarios

in order to avoid changing the font type in the ticks one should include the following line in lines around 323, 539:

Comment only
17 Jul 2015 Rong Yu

It is very helpful when I am making boxplots!!! Thank you!

02 Jun 2015 Steve Peppin

Thanks! Very nice

03 Nov 2014 Imtiaz

Imtiaz (view profile)

19 Oct 2014 Konstantinos

I know it is an old file and coding standards have changed but this file is over 500 lines of code while it could be half the size

There is a lot of repetition which leads to errors out of copy pasted parts e.g.

line 212
elseif length(tickx) == 0;

should be

elseif length(tickposx) == 0;

28 Sep 2014 Pablo

Pablo (view profile)

27 May 2014 Chen

Chen (view profile)

it is not very good

Comment only
02 May 2014 Maha

Maha (view profile)

Excellent function, works really well. I made a few changes that extends this program for semilogx, semilogy, and loglog plots. Check it out here:

21 Jan 2014 seeden

seeden (view profile)

16 Oct 2013 Jakob Sievers

Jakob Sievers (view profile)

Great. Though I had to apply a segment of 'parent',h to all the text commands for it to work as intended when working with several plots in a subplot.

10 May 2013 Alexandros Iliopoulos

14 Jan 2013 Stan

Stan (view profile)

Very helpful, thank you!

29 Nov 2012 asdas

asdas (view profile)

it appears that this function does not work with log-log plots...

Comment only
19 Jul 2012 pietro

pietro (view profile)

Hi this is a very usefull tool. Is it possible to use it for color axis thick labels? I tried to give the color axis axis handle, but it doesn't work.


29 Jun 2012 Thomas

Thomas (view profile)

Great Tool,

but if try to use it on a Diagram with a logarithmic scaled y-axis the xlabels disapear. When using ist with a log scaled x-axis the ylabels disapear.

24 Apr 2012 JoseMauricio

Hi!! Can I use Tick in 3D diagrams?

13 Apr 2012 Dhayalan

I tried for Semilog bar plot. But it is not functioning. All my values are positive, so no problem with semilog in Y axis. Once i change the scale to semilog and run this code, nothing appears in Xticks. Any help?


04 Feb 2012 Bret

Bret (view profile)

Worked first time!

19 Aug 2011 Lucila

Lucila (view profile)

29 Jul 2011 Patrick

To get it to work with log axes I replaced




Comment only
17 Jul 2011 Jay Cheng

I am working on 3D plots. How to add tickz......... please.

14 Jul 2011 Namaka

Namaka (view profile)

Thanks for the file!

But I found a small bug:
If I make my tick labels beforehand then use this version of the function:
It re-assigns my tick labels to the default.

I did a quick-fix by copying the lines tickposx = get(h,'XTick'); and
'set(h,'XTickLabel',tickposx);' (located around line 134), and pasting them into the preceding if-statement. then I deleted the extra 'set(h,'XTickLabel',tickposx); '. However, beware! This fix may have introduced other errors that I haven't caught...

Comment only
05 Apr 2011 J G

J G (view profile)

04 Nov 2010 ?ukasz

?ukasz (view profile)

It doesn't work with semilogx correctly.
check the Y label.

26 Oct 2010 Murat Cihan Yüksek

Excellent contribution, easy to use, perfectly useful for thesis work... Thank you.. Sorry about my previous post. It was my first.. This contribution deserves full rating..

Comment only
04 Sep 2010 Santiago

Good work. It could be improved by allowing to format the y axis only independently of the x axis. Default action should be to do nothing. There are also problems with log plots, ylabels move out of the figure sometimes and xlabels are formatted only in the exponent.

Comment only
13 May 2010 John

John (view profile)

Great stuff, however I am finding that the rotated labels are not centered but are right-justified. For example:


09 Feb 2010 Aniket

Aniket (view profile)

In response to comment suggested by Eric above (Dated: 11 Feb 2009):
I tried copying unicode characters from word, and they show ok in the script editor, but on the figure, they show as "?".
Any one else has noticed this, and have a solution??
I dont want to download this script file just to write character π in the ticklabel.

Comment only
31 Jul 2009 Nicolas Ferlay

Dear fellows,

I did detect a small problem:
it works when I write as the ticklabel '$10^{3}$', or '$10^{+3}$', not with '$10^{-3}$' : the minus sign is not understood !
How can it be ?


Comment only
24 Jul 2009 Paul

Paul (view profile)

A very useful program; however, it doesn't seem to work when I move the y-axis to the right with set(gca,'yaxislocation','right') - does anyone know how to do this?

The reason I ask is because I manually create colourbars with imagesc (so I have better control over the tick labels etc.) and I want the yaxis to sit on the right...

Any help is greatly appreciated.

28 May 2009 Daniel Crispell

Very nice and very useful. One comment- I believe the 'if' statement on line 303 should be >=, not > so that if only one option is being set the block will be entered.

24 May 2009 Jeffrey

Jeffrey (view profile)

Great work. My only complaint is that the default behavior should be do nothing, not add degrees. But that was easy enough to fix in the mfile.

20 Apr 2009 Patrick Toche

This is a very useful submission. I'm sorry that I submitted 1 star above, I tried to cancel but couldn't. I think it happened when I refreshed my browser. If someone knows how to cancel it, please by all means do. I meant to give 5 stars.

I just want to say that I made a minor extension to this script. It should appear under my name, it's a very trivial extension: I have Introduced a distinction between offsets for the horizontal axis offset_x and vertical axis offset_y. This is useful if your x-axis and y-axis do not cross at the origin. This extension gives you independent control of the offset for the x-axis labels and y-axis labels. If you're interested it should soon appear under my name. I don't have the reference now as I only just uploaded it. Thanks again to Alexander.

20 Apr 2009 Patrick Toche

11 Feb 2009 Eric

Eric (view profile)

Obviously the alternative above is limited to the unicode character sets and is not as flexible as the TeX interpreter

Comment only
11 Feb 2009 Eric

Eric (view profile)

If you have a word processor (like MS WORD) that allows you to insert special symbols like ½ ° µ you can just copy and paste them directly into MATLAB. If using an m file just copy paste these characters into your quoted character array and pass it to your call to set tick labels. The characters are not exactly the same as the TeX characters so make sure you are consistent with this strategy.

Comment only
10 Feb 2009 Ben Woodacre

You can fix the problem I described above by saving the text labels' positions and then restoring them after invoking format_ticks(). The following code could be shrunk a tad, but it's general enough in case you are using any type of units for the Position property.

% Save label positions
xl = get(gca,'xlabel');
yl = get(gca,'ylabel');
orig_label_units = get( xl, 'Units');
set([xl yl], 'Units','pixels');
xp = get( xl, 'Position');
yp = get( yl, 'Position');
% Generate the text object ticks (changing labels' Position):
[hx, hy] = format_ticks(gca,'{}','{}')
% Restore original label Position and Units properties:
set( xl, 'Position', xp);
set( yl, 'Position', yp);
set([xl yl], 'Units', orig_label_units);

09 Feb 2009 Ben Woodacre

This is just what I have been looking for.

But when I add X and Y axis labels, they are positioned on top of the new text object ticks when MATLAB detects that the axis doesn't have proper axes ticks anymore.

Is there a way to turn off this last re-layout?

22 Jul 2008 Oskar Vivero

This is a great submission! I only edited a couple of lines to fit my needs (turned off the latex interpreter in order to run the figure through laprint.m). Great job!

07 Apr 2008 Ozgur Akman

Top-notch! Really useful function.

18 Nov 2007 Martin Fischbach

Works like a charm!

Thanks for your effort!

12 Oct 2007 John Nat

Great function. It worked flawlessly in my plots.
However, it pains me to see the great lengths the author had to go simply because Matlab lacks support for LaTeX rendering in the Tick Labels. I hope this support is included in future versions.

Contact us