- 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.
Scatterhist: width of Boxplot
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Fabian Teichmann
el 16 de Abr. de 2021
Comentada: Fabian Teichmann
el 1 de Nov. de 2021
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
0 comentarios
Respuesta aceptada
Adam Danz
el 16 de Abr. de 2021
Editada: Adam Danz
el 19 de Abr. de 2021
> 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
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).
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Distribution Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!