Plotting Multiple Box plot in same graph same x axis

51 次查看(过去 30 天)
I have a data for 5 samples, and for 3 months.
I want to plot 5 box plots for every months. Which means in X-axis I will have January, Mars and April (3 values).
And I want to plot the 5 boxes plot in each month (different color ofc).
I search in the web and unfortunaly I didn't find any case like this, I don't know if it's possible to plot something like that.

采纳的回答

Voss
Voss 2022-2-25
Maybe something like this?
colors = 'rgbym';
for ii = 1:5
x1 = rand(5,1);
x2 = rand(10,1);
x3 = rand(15,1);
x = ii+[x1; x2; x3];
g1 = repmat({'January'},5,1);
g2 = repmat({'Mars'},10,1);
g3 = repmat({'April'},15,1);
g = [g1; g2; g3];
boxplot(x,g,'BoxStyle','filled','Color',colors(ii));
hold on
end
  13 个评论

请先登录,再进行评论。

更多回答(1 个)

Rik
Rik 2022-2-25
编辑:Rik 2022-2-25
You can group them in bins from 1 to 15 and tweak the x labels to match your needs.
See the documentation for how to use 'GroupByColor'.
data=cell(5,3);
for n=1:numel(data)
data{n}=randi(n)*randn(100,1);
end
grouping=cell(size(data));
for n=1:numel(data)
grouping{n}=n*ones(size(data{n}));
end
grouping=[grouping{:}];
data=[data{:}];
boxchart(grouping(:),data(:))
xticks(2.5:5:12.5)
xticklabels({'January','March','April'})
  4 个评论
Tesla
Tesla 2022-2-26
Thank you a lot,
And how to put my data?
Because the arrays of my data have not the same dimensions.
For example data1 is [0.5 0.78], data2 [0.4 0.6 0.12] data3 [0.9 0.4 0.47]...
Rik
Rik 2022-2-26
The point is that each variable should be a vector. The best syntax to ensure that depends on your exact data.
Also, if this answer solved the problem, please consider marking it as accepted answer.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by