MATLAB Answers

John
2

How to change text size in boxplot

John
さんによって質問されました 2013 年 1 月 18 日
最新アクティビティ roger
さんによって 回答されました 2016 年 12 月 14 日
Hi,
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.
Thank you

  0 件のコメント

サインイン to comment.

タグ

3 件の回答

Daniel Shub
回答者: Daniel Shub
2013 年 1 月 18 日
編集済み: Daniel Shub
2013 年 1 月 18 日
 採用された回答

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);
load carsmall
boxplot(MPG, Origin);
The second is to change the text label after plotting
load carsmall
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.
EDIT
If you only have the figure file
hFig = figure;
load carsmall
boxplot(MPG, Origin);
saveas(hFig, 'temp_figure');
close(hFig);
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);

  1 件のコメント

John
2013 年 1 月 18 日
Hi,
I only have the Figure file and not the actual data. Can you set the Figure equal to h? How would you do that?
Thanks

サインイン to comment.


roger
回答者: roger
2016 年 12 月 14 日

boxplot([LEAD,own],'Notch','on','Labels',{'LEAD','OWN'});
set(gca,'XTick',1:2)%2 because only exists 2 boxplot
set(gca,'XTickLabel',{'LEAD','OWN'},'FontSize',20)

  0 件のコメント

サインイン to comment.


回答者: Rodrigo Diaz 2016 年 9 月 7 日

Thanks Daniel Shub. The second way really works very well.

  0 件のコメント

サインイン to comment.



Translated by