How to change text size in boxplot
125 views (last 30 days)
Show older comments
Would anybody know how to change the size of the font on the x-axis labels in a boxplot. For example I want to make the label "Urban Congested" larger?
I cannot figure out how to do it in the axis property editor.
Daniel Shub on 18 Jan 2013
Edited: Daniel Shub on 18 Jan 2013
I can think of two ugly hacks that work ...
The first is to set the default font size of all text labels for the plot
h = figure;
set(h, 'DefaultTextFontSize', 30);
The second is to change the text label after plotting
h = boxplot(MPG, Origin);
set(findobj(get(h(1), 'parent'), 'type', 'text'), 'fontsize', 30);
It is not clear to me what boxplot is actually returning. It is an array of handles, when I would have expect the group. My guess is if you look through the code of boxplot you can find a cleaner way.
If you only have the figure file
hFig = figure;
You can open the figure and get the handle to the figure
hFig = open('temp_figure.fig');
The goal is then to find the boxplot object. Unfortunately, the boxplot object this is just an hggroup object and there might be lots of hggroup objects which are not boxplot objects. I don't know how to figure out if an hggroup object is actually a boxplot object. You can however, click around and select objects until gco works:
set(findobj(get(gco, 'Children'), 'type', 'text'), 'fontsize', 30);
More Answers (2)
roger on 14 Dec 2016
set(gca,'XTick',1:2)%2 because only exists 2 boxplot
Rodrigo Diaz on 7 Sep 2016
Thanks Daniel Shub. The second way really works very well.
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!