Tiled layout with boxplot and 'Padding', 'none'

16 visualizaciones (últimos 30 días)
Benoit Espinola
Benoit Espinola el 17 de Jun. de 2020
Editada: Matt J el 16 de Abr. de 2021
When using 'Padding','none' for my tiled layout. The box plots are not centered and are cropped inside the figure.
figure
t = tiledlayout(1,2, 'Padding', 'none');
nexttile;
boxplot(randn(10,5));
nexttile;
boxplot(randn(10,5));
Result:
Why is that and how to solve it?
  2 comentarios
Kevin Joshi
Kevin Joshi el 17 de Jun. de 2020
Suggestion: Use tight_subplot
https://in.mathworks.com/matlabcentral/fileexchange/27991-tight_subplot-nh-nw-gap-marg_h-marg_w
Matt J
Matt J el 16 de Abr. de 2021
'Padding'='none' is not a documented setting. The choices are either 'loose','compact', or 'tight'.

Iniciar sesión para comentar.

Respuesta aceptada

Adam Danz
Adam Danz el 16 de Abr. de 2021
Why this is happening
The boxplot function uses a local function setLabelappdata() to adjust the axes' OuterPosition, PositionConstraint & LooseInset properties after the boxplots are rendered. However, these properties are not editable in axes created by TiledLayout. Matlab throws a warning. Hopefully MathWorks will either address this problem or make the position properties of tiledChartLayout objects editable.
Warning: Unable to set 'Position', 'InnerPosition', 'OuterPosition', or
'ActivePositionProperty' for objects in a TiledChartLayout
Workarounds
1. In your case, set padding to compact instead of none (see other updates to Padding options in r2021a).
2. You can turn the warning off (see the answer from this similar thread).
3. Use axes or subplot instead of tiledlayout.
  1 comentario
Matt J
Matt J el 16 de Abr. de 2021
Editada: Matt J el 16 de Abr. de 2021
There are also alternative boxplot routines on the File Exchange that you could try, which do not attempt the property settings that Adam mentions. This one, in particular, seems to work,
t = tiledlayout(1,2, 'Padding', 'tight');
nexttile;
boxplotx(randn(10,5));
nexttile;
boxplotx(randn(10,5));

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Geographic Plots en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by