Boxplot help to get 4 plots into 1 graph of 5.

4 Ansichten (letzte 30 Tage)
Bradley Cory
Bradley Cory am 29 Jun. 2018
Bearbeitet: dpb am 29 Jun. 2018
I'm trying to compare boxplots in the same graph.
However, my code in placing the data into 4 different boxplots.
figure
subplot(2,2,1)
boxplot(ft_max_data1)
subplot(2,2,2)
boxplot(ft_max_data2)
subplot(2,2,3)
boxplot(ft_max_data3)
subplot(2,2,4)
boxplot(ft_max_data4)
subplot(2,2,5)
boxplot(ft_max_data5)
How would I keep the boxes on the same figure?

Antworten (1)

dpb
dpb am 29 Jun. 2018
Bearbeitet: dpb am 29 Jun. 2018
If you plot multiple boxplot into the same axis, they'll overlay each other for 1:N variables where N is the composite of number in each of the variables passed. In your case I would presume they're probably all the same.
The boxplot as implemented has no provision for a positioning variable along the x-axis; all it has as an option is a grouping variable and (just tried it to see) if one uses it on a matrix, it combines all columns of each group into a single box for the group.
The only way to place multiple boxes on a single axes without them overlaying each other would be something like
boxplot([ft_max_data1 ft_max_data2 ft_max_data3 ft_max_data4 ft_max_data5])
and then use XTickLabel to write identifying text for each of the variables.
Coding would be simpler if you avoided the use of sequentially-numbered named variables and used array or cell array or the like instead so can make effective use of Matlab indexing syntax.
  2 Kommentare
Bradley Cory
Bradley Cory am 29 Jun. 2018
Thank you, Some really great insight. I'm learning to code and have a limited knowledge of the field. The plot from your above just gave me a single box, But Ill keep trying. Thank you for the advice. I'll look into the indexing syntax.
dpb
dpb am 29 Jun. 2018
Bearbeitet: dpb am 29 Jun. 2018
" above just gave me a single box,..."
You'll get a box for each column in the input array or one for a vector. I had presumed a column vector array; to make the above work for row vectors you need to write
boxplot([ft_max_data1.' ft_max_data2.' ft_max_data3.' ft_max_data4.' ft_max_data5.'])
or
boxplot([ft_max_data1; ft_max_data2; ft_max_data3; ft_max_data4; ft_max_data5].')
to create a 2D array of variables by column. The first transposes each vector and concatenates them; the second concatenates the row vectors vertically and then transposes that array; same result in the end.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by