Hello,
ist it possible to change the width of the left boxplot in the following example taken from your website? I'd like the width of the left boxplot to be the same as the height boxplot below the scatter plot. Can anyone help?
load fisheriris.mat;
x = meas(:,1);
y = meas(:,2);
h = scatterhist(x,y,'Group',species);
hold on;
clr = get(h(1),'colororder');
boxplot(h(2),x,species,'orientation','horizontal',...
'label',{'','',''},'color',clr);
boxplot(h(3),y,species,'orientation','horizontal',...
'label', {'','',''},'color',clr);
set(h(2:3),'XTickLabel','');
view(h(3),[270,90]); % Rotate the Y plot
axis(h(1),'auto'); % Sync axes
hold off;
Thanks in advance.
Cheers,
Fabian

 采纳的回答

Adam Danz
Adam Danz 2021-4-16
编辑:Adam Danz 2021-4-19
> I'd like the width of the left boxplot to be the same as the height boxplot below the scatter plot [in scatterhist]
Key points to know
  • In h=scatterhist(__), h is a 1x3 array of axis handles where h(1) is the scatter axes, h(2) is the horizontal axis, and h(3) is the vertical axis.
  • The position of axes is defined by h(n).Position for axis n which returns a 1x4 vector identiying the [x coordinate of lower-left corner, y coordinate of lower-left corner, width height].
  • The position units are defined in h(n).Units which are normalized by default.
  • To equate the width of one axis with the height of another axis, you need to use non-normalized units unless your figure is perfectly square.
Solution
origUnits = get(h(2:3),'Units');
set(h(2:3), 'Units', 'Pixels')
sizeDiff = h(3).Position(3) - h(2).Position(4);
h(3).Position(3) = h(2).Position(4);
h(3).Position(1) = h(3).Position(1)+sizeDiff;
set(h(2:3),{'Units'}, origUnits)
Note that resizing the figure will result in resizing the axes so the width of axis 3 will no longer match the heigh of axis 2 unless the figure resize maintains height:width ratio. You could remove the last line in my solution but that will potentially cause other problems (you can try it and see what I mean).

1 个评论

Thanks alot that worked fine for me. Sorry for the late reply =)

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by