File Exchange

image thumbnail

fix_xticklabels - automatically convert xticklabels to multiple line format

version 1.1.0.0 (2.47 KB) by Mikhail Erofeev
It will determine maximum allowed width of XTickLabels and convert them into multiple line format

12 Downloads

Updated 17 Aug 2015

From GitHub

View Version History

View license on GitHub

FIX_XTICKLABELS will determine maximum allowed width of long XTickLabels and convert them into multiple line format to fit maximum allowed width

IN:
handle [optional] - axes handle (defaults to gca)
margins [optional] - relative margins width (defaults to 0.1)
texopts [optional] - cell array of addtitional text formating
options (defaults to {} )

OUT:
ht - column vector of handles for created text objects

This code was derrived from MY_XTICKLABELS by Pekka Kumpulainen
http://www.mathworks.com/matlabcentral/fileexchange/19059-myxticklabels
EXAMPLE:
figure;

bar(rand(1,4));
set(gca,'XTickLabel',{'Really very very long text', ...
'One more long long long text', ...
'Short one','Long long long text again'});
fix_xticklabels();

figure;

bar(rand(1,4));
set(gca,'XTickLabel',{'Really very very long text', ...
'One more long long long text', ...
'Short one','Long long long text again'});
fix_xticklabels(gca,0.1,{'FontSize',16});

Mikhail Erofeev 07.06.2013
Pekka Kumpulainen 12.2.2008

Cite As

Mikhail Erofeev (2021). fix_xticklabels - automatically convert xticklabels to multiple line format (https://github.com/merofeev/fix_xticklabels), GitHub. Retrieved .

Comments and Ratings (16)

Soumyajit Dey

Thomas Binns

Rahul Wadhwani

GunnarG

Jeff Slee

Nice function. Works great!

Daniel Barron

Deep Shah

Mario Solis

Majid

thanks. it was amazing and very useful for me.

Nice Solution !

Jianhui Jiang

Very useful. Thanks a lot.

Alex Warning

Thank you!!

Mikhail Erofeev

Simon! Can you please send me ( merofeev AT graphics.cs.msu.ru ) some piece of code, which illustrates the problem you described, so I can try to find a solution.

Simon

Hey Mikhail, nice script! But using xlabel the plot doesn't look nice anymore, because the xlabels and the xticks overlay. Any hints to fix this?

Tymofii Tereshchenko

Perfect!

John Adcox

Does what it says!

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

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!