How do I create boxplots of defined size?

5 views (last 30 days)
Franziska
Franziska on 24 Oct 2012
Hello!
I know that the total size of a figure can be determined by setting the 'PaperSize' and 'PaperPosition' properties. The size of the plots as they are framed by the axes can be adjusted by drawing axes with defined position.
axes('Position',[left bottom width height]);
However, I have found that this does not work for boxplots, i.e. boxplots cannot be drawn in predefined axes - as soon as the boxplot command is called, matlab draws new axes of different position. Can anyone tell me how I can obtain boxplots of defined size?
PS: the axes defined in boxplot(axes('Position',[left bottom width height]),data) are also overruled by the boxplot routine, so this is also not a solution.
Thanks, Franzi
  3 Comments
Franziska
Franziska on 24 Oct 2012
Thanks for the fast answer. However, determining the size of the boxplot with boxplot(axes,data) does not work properly. I send a piece of code that should generate a figure which consists of 2 subplots with the same size. However, these subplots are obviously not identical.
%% code
clear; close all;
% sample data
data=randn(100,10);
% boxplot
figure; set(gcf,'Units','inch'); set(gcf, 'PaperPositionMode', 'manual');
xSize=5; ySize=2.5;
set(gcf, 'PaperSize', [xSize ySize]); set(gcf,'PaperPosition',[0 0 xSize ySize]); set(gcf,'Position',[0 0 xSize*2 ySize*2]);
boxplot(axes('Position',[0.1/xSize 0.1/ySize 2.3/xSize 2.3/ySize]),data);
axes('Position',[2.6/xSize 0.1/ySize 2.3/xSize 2.3/ySize]); plot(0.1:0.1:4,sin(0.1:0.1:4));
% print
print(gcf,'-depsc','~/Desktop/boxplotSizeIssue.eps');

Sign in to comment.

Answers (1)

Sean de Wolski
Sean de Wolski on 24 Oct 2012
Edited: Sean de Wolski on 24 Oct 2012
If you go to the documentation for boxplot:
doc boxplot
The third options is:
  • boxplot(axes,X,...)
Here you specify the axes handle on which to plot the boxplot:
hAx = axes(blah blah blah);
boxplot(hAx,blah blah blah);
More
In that case, manually resize the axes after creating the boxplot:
ax = findall(gcf,'type','axes');
set(ax(2),'position',[0.1/xSize 0.1/ySize 2.3/xSize 2.3/ySize])

Community Treasure Hunt

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

Start Hunting!