MATLAB Answers

How to do tiledlayout for Boxplots?

36 views (last 30 days)
Shaoni Nandi
Shaoni Nandi on 21 May 2020
Answered: Adam Danz on 30 Jun 2020 at 14:56
I am trying to do a tiledlayout for MATLAB boxplots. My code is:
tiledlayout('flow');
boxplot(randn(10,5));
nexttile;
boxplot(randn(10,5)+5);
nexttile;
boxplot(randn(10,5)-6);
nexttile;
boxplot(randn(10,5));
But I always get the below warnings
Warning: Unable to set 'Position', 'InnerPosition', 'OuterPosition', or
'ActivePositionProperty' for objects in a TiledChartLayout
> In boxplot>renderLabels/setLabelappdata (line 3012)
In boxplot>renderLabels (line 2913)
In boxplot (line 407)
Any clues please?

  0 Comments

Sign in to comment.

Accepted Answer

Sai Sri Pathuri
Sai Sri Pathuri on 26 May 2020
The boxplot function sets the position of axes (If the axes are not UI axes -> line 3012) and according to the warning, it can not be set for tiled layout. This might be the reason for the warning. If you do not want the warning to show up, you may use
warning('MATLAB:handle_graphics:Layout:NoPositionSetInTiledChartLayout','off')
And for all the plots to be shown, use nexttile before first plot. Refer this example.
tiledlayout('flow');
nexttile;
boxplot(randn(10,5));

  2 Comments

Benoit Espinola
Benoit Espinola on 17 Jun 2020 at 6:56
That (exception in behaviour for boxplot with tiled layouts compared to other basic matlab plotting functions) is terrible programming from Mathworks' side.
Babak Zandi
Babak Zandi on 30 Jun 2020 at 14:29
I have also received this warning message. Such simple things shouldn't be an issue for a company like MathWorks.

Sign in to comment.

More Answers (1)

Adam Danz
Adam Danz on 30 Jun 2020 at 14:56
As of r2020a, you can use the new boxchart() function which is a "stand alone visualization" version of the boxplot() function but with some limitations with some of the optional properties of the boxplot.
The boxchart() objects can be plotted on the tiledlayout without a warning message.
% requires release >= r2020a
tiledlayout('flow');
nexttile;
boxchart(randn(10,5));
nexttile;
boxchart(randn(10,5)+5);
nexttile;
boxchart(randn(10,5)-6);
nexttile;
boxchart(randn(10,5));

  0 Comments

Sign in to comment.