File Exchange

image thumbnail


version (1.89 KB) by Pekka Kumpulainen
Replaces XTickLabels with "normal" texts accepting multiline texts and TEX interpreting


Updated 05 Mar 2008

View License

MY_XTICKLABELS replaces XTickLabels with "normal" texts accepting multiline texts and TEX interpreting and shrinks the axis to fit the texts in the window.

Cite As

Pekka Kumpulainen (2020). MY_XTICKLABELS (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (22)

Rajib Mukherjee

Walter Bast

Matt J

Youngsuk Ko


Martin Schrimpf

Artem Kabannik

Then subsequent code should look like:
ht(ii) = text('String',xtickstring{ii}, ...
'Units','data', ...
'VerticalAlignment', 'top', ...
'HorizontalAlignment', 'center ', ...
'Position',[xtickpos(ii) Ybot], ...
'Tag','MUXTL', 'Parent', Ha);

Artem Kabannik

It seems that I have found a bug at line 54:

In the code:
Ybot = min(get(gca,'YLim'));

I changed it to:
Ybot = min(get(Ha,'YLim'));

Liaofan Lin

Mikhail Erofeev


Tanks! You're a good guy.

Mauro Donzelli

Mauro Donzelli

Kristofer Kusano

Very nice, thanks for posting this

Kristofer Kusano


This is a very useful tool. One suggestion though: the text() command gets confused if there is more than one axis, so maybe you can set the current axis to Ha with axes(Ha) before the cell '%% Make XTickLabels'.

Du Xiao

Perfect, Thank you very much for your help!

Andrew Schwartz

Works for the most part. Manageable issue: labels remain in same figure positions when changing the axis using axis(xylims) rather than moving to the new correct locations relative to the axes. Solution for now is of course to only call my_xticklabels after axis limits have been set.

Dominik Bach

After switching to (R2009a), the squeeze axes part of the function does not work any more. Converting the axes units to pixels produces negative values for some reason, hence the function crashes. Otherwise still very helpful.

Wilbert Zarco

It solves the 'xticklabels' limitation of lacking Tex capabilities, and I think also the work for the matlab team to implementing it. Great job!

Claude Mueller

worked great for me! thanks!!

Bob Farrell

Perfect. Just what I was looking for. It does what it says and was a drop-in into my code. I needed multi-line xtick labels, and the TEX characters were a bonus.

MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux