Plot on Boxplot on the same graph
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 :)
0 Kommentare
Akzeptierte Antwort
dpb
am 4 Okt. 2022
Bearbeitet: dpb
am 4 Okt. 2022
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 Kommentare
dpb
am 4 Okt. 2022
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
am 4 Okt. 2022
Bearbeitet: dpb
am 4 Okt. 2022
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
