4.88889

4.9 | 12 ratings Rate this file 229 downloads (last 30 days) File Size: 17.5 KB File ID: #15986

Format Tick Labels

by Alexander Hayes

 

19 Aug 2007 (Updated 20 Aug 2007)

No BSD License  

Replace Tick Label with Specified Formattable Objects.

Editor's Notes:

This was a File Exchange Pick of the Week

Download Now | Watch this File

File Information
Description

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.

Acknowledgements
This submission has inspired the following:
Format Tick Labels (Extended), tick2text: create easy-to-customize tick labels
MATLAB release MATLAB 7.3 (R2006b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (15)
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.

18 Nov 2007 Martin Fischbach

Works like a charm!

Thanks for your effort!

07 Apr 2008 Ozgur Akman

Top-notch! Really useful function.

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!

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?

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

11 Feb 2009 Eric

SIMPLE ALTERNATIVE
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.

11 Feb 2009 Eric

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

20 Apr 2009 Patrick Toche  
20 Apr 2009 Patrick Toche  
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.

24 May 2009 Jeffrey

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.

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 Jul 2009 Paul

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.

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 ?

Nicolas

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
annotation Alexander Hayes 22 Oct 2008 09:23:32
customization Alexander Hayes 22 Oct 2008 09:23:32
tick label Alexander Hayes 22 Oct 2008 09:23:32
axes Alexander Hayes 22 Oct 2008 09:23:32
figure Alexander Hayes 22 Oct 2008 09:23:32
plot Alexander Hayes 22 Oct 2008 09:23:32
latex Ben Woodacre 10 Feb 2009 01:48:44
axes Ben Woodacre 10 Feb 2009 01:48:53
figure Ben Woodacre 10 Feb 2009 01:49:02
tick label Ben Woodacre 10 Feb 2009 01:49:03
annotation ana molina 30 Apr 2009 02:32:43
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com