Plot on Boxplot on the same graph

3 ビュー (過去 30 日間)
KonPol
KonPol 2022 年 10 月 4 日
編集済み: dpb 2022 年 10 月 4 日
Hello potential ansewrer,
I have let's say 9 differnent monthly matrices, days*hours (e.g. January 31*24).
Now I have calculated the hourly averages through the 31 days (=1*24 values) for each of the 4 matrices.
Then I am try to plot on the same graph, a boxplot of each month and by using hold on its hourly averages.
Of course, matlab does not accept this as monthly boxplots appear on position x=1 and its hourly averages appear x=1:24 so there are not consistent.
As the periods are the same I do not know if the use of multiple x-axis would help.
Boxplots:
Hourly Averages:
Any help :)

採用された回答

dpb
dpb 2022 年 10 月 4 日
編集済み: dpb 2022 年 10 月 4 日
Shift/Rescale the hourly times to be centered about the 1:N values.
boxplot(T)
hold on
W=0.8; % fractional width of each box -- arbitrary, adjust to suit/fit
for i=1:9
t=rescale(1:24,i-W/2,i+W/2); % normalize about month index
plot(t,H(:,i)); % plot hourlies against normalized times
end
  3 件のコメント
dpb
dpb 2022 年 10 月 4 日
What could be simpler than the above? It IS using hold on after creating the boxplot.
T is your array; create the boxplot first as shown from it and then add the other data.
Oh...I see, I changed horses in midstream -- the other T inside the loop should be H, the hourly data by month array instead of the boxplot data. My bad, didn't realize had done that.
Without having posted data or specific variables to work with, we're left just trying to make up generic stuff to fit...
dpb
dpb 2022 年 10 月 4 日
編集済み: dpb 2022 年 10 月 4 日
Here's an example that the idea works with just arbitrary data --
boxplot(randn(30,9)) % a boxplot of 30 "days" by 9 months
hold on
t=1:24; % the 24 hours vector
W=0.8;
t1=rescale(t,-W/2,+W/2); % rescale around zero as base
for i=1:9 % over each month group
plot(i+t1,randn(24,1),':') % add a centered graph over each bar in turn
end
xticklabels(month(datetime(2022,1:9,1),'shortname'))
Just use your data in place...
Looks like W could/should be a little smaller for the nine boxes; the range of the added lines is somewhat wider than the boxes themselves. You'll have to 'spearmint and see what is proper adjustment.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by