BoxPlot with datetime in Y-axis?
조회 수: 2 (최근 30일)
이전 댓글 표시
How can I draw a boxplot with datetime value in the y axis? (ex: if arrival times of a vehicle is available over a year, to show the mean, median arrival times)
댓글 수: 0
채택된 답변
Adam Danz
2019년 4월 18일
편집: Adam Danz
2020년 12월 19일
"How can I draw a boxplot with datetime value in the y axis? "
arrivalTime = datetime('Jan 01, 2001 12:00') : 0.2 : datetime('Jan 01, 2002 12:00');
boxplot(datenum(arrivalTime));
datetick('y') %more options: https://www.mathworks.com/help/matlab/ref/datetick.html
"if arrival times of a vehicle is available over a year, to show the mean, median arrival times"
As the matlab documentation indicates, boxplot() displays the median value. You'll have to show the mean value manually.
hold on
plot(1, mean(datenum(arrivalTime)), '*', 'DisplayName', 'Mean')
legend()
Instead of manually specifying x=1 for the center of the box plot, you could get the boxplot centers using,
bh = findobj(gca,'type','line','tag','Box'); % handles to rectangular boxes
xdata = vertcat(bh.XData);
boxCenters = (max(xdata,[],2) - min(xdata,[],2))/2 + min(xdata,[],2);
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
