Change the distance between boxplots

I use following code to create the boxplot. I want to change the distance between the two boxes. However, I cant find any property to control the distance.
rng default % For reproducibility
x = randn(100,15);
figure
boxplot(x,'PlotStyle','compact')
set(gca,'FontSize',10,'XTickLabelRotation',90)
Also, the XTickLabelRotation does not change the xtick label orientaiton. How can I change orientaion?

 採用された回答

dpb
dpb 2021 年 11 月 13 日
編集済み: dpb 2021 年 11 月 13 日

0 投票

  1. boxplot doesn't support variably-spaced box locations.
  2. use 'LabelOrientation','Horizontal' to maintain normal tick label orientation.
On the latter, why TMW chose to create a different name for the property instead of maintaining consistency with all other plotting routines is one of those maddening inconsistencies they love to introduce -- more and more so recently, it seems.
I suppose it goes to the specialized plot that's to be easy to use and so doesn't need/shouldn't have all the bells and whistles of a generic axes object. So, they provide the two choices of rotated or not with a different name. I suppose there is some logic there...

4 件のコメント

Imran Kanjoo
Imran Kanjoo 2021 年 11 月 13 日
I see the space between the two boxes is much higher than it should be.
dpb
dpb 2021 年 11 月 13 日
編集済み: dpb 2021 年 11 月 14 日
That's totally dependent upon the number of boxes and the size of the axes object -- boxplot spreads them across the given axes size.
subplot(2,1,1)
boxplot(randn(100,15),'PlotStyle','compact','LabelOrientation','horizontal')
subplot(2,1,2)
boxplot(randn(100,25),'PlotStyle','compact','LabelOrientation','horizontal')
produces
Alternatively,
boxplot(randn(100,15),'PlotStyle','compact','LabelOrientation','horizontal')
hAx=gca; hAx.Position(3)=hAx.Position(3)*15/25;
Reduce the width of the axes object.
I don't know what other behavior one would expect -- otherwsie the axis box would be left with a bunch of empty space if the number of bars plotted aren't spread out over the axis.
I suppose it is possible they could have implemented it at a given spacing and let the axes follow, but that doesn't match the behavior of any other plotting routine--they're chiildren of the axis, so they fill what they find.
Imran Kanjoo
Imran Kanjoo 2021 年 11 月 14 日
Hi, thanks for reducing the width of the axes object. The last lines of codes work for me. How can I reduce the verticle axes height?
dpb
dpb 2021 年 11 月 14 日
The position vector is a 4-vector of [left bottom width height]. Adjust as desired. See the doc on axes properties for all the details.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品

リリース

R2018b

タグ

質問済み:

2021 年 11 月 13 日

コメント済み:

dpb
2021 年 11 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by