Boxplot with scaled x-axis?

조회 수: 6 (최근 30일)
Zel
Zel 2022년 8월 26일
댓글: Cris LaPierre 2022년 8월 26일
I'm trying to plot temperature data that is dependent on concentration (with temperature being the y axis and concentration the x). How do I create a plot that is scaled for the x variables (such that if some concentrations are closer the boxes are also closer)? I'm loading large sets of data and the previous examples I've seen are only drawn matrixes. Any help is appreciated. Thanks!

답변 (1개)

Cris LaPierre
Cris LaPierre 2022년 8월 26일
Use boxchart and specify the xgroupdata input.
Here's an example that orders and spaces the groups based on Month
tsunamis = readtable('tsunamis.xlsx');
tsunamis(1:8,["Month","Cause","EarthquakeMagnitude"])
ans = 8×3 table
Month Cause EarthquakeMagnitude _____ __________________ ___________________ 10 {'Earthquake' } 7.6 8 {'Earthquake' } 6.9 12 {'Volcano' } NaN 3 {'Earthquake' } 8.1 3 {'Earthquake' } 4.5 5 {'Meteorological'} NaN 11 {'Earthquake' } 9 3 {'Earthquake' } 5.8
idx = contains(tsunamis.Cause,'Earthquake');
earthquakes = tsunamis(idx,:);
% Delete one month of data to show gap in figure
earthquakes(earthquakes.Month==3,:) = [];
boxchart(earthquakes.Month,earthquakes.EarthquakeMagnitude)
figure
earthquakes = tsunamis(idx,:);
% Change spacing of one group by adjusting the month number
earthquakes.Month(earthquakes.Month==3) = 2.5;
boxchart(earthquakes.Month,earthquakes.EarthquakeMagnitude)
  댓글 수: 1
Cris LaPierre
Cris LaPierre 2022년 8월 26일
Just a comment. The xaxis here is optimized for categorical data, meaning X is really group number (integer values). The resulting output may not look like you want. This means you might have to adjust other parameters to account for your xgroupdata (e.g. BoxWidth).
tsunamis = readtable('tsunamis.xlsx');
idx = contains(tsunamis.Cause,'Earthquake');
earthquakes = tsunamis(idx,:);
earthquakes.Month=earthquakes.Month/10;
% BoxWidth uses default width, though X scale is now .1-1.2
boxchart(earthquakes.Month,earthquakes.EarthquakeMagnitude)
% Adjust BoxWidth to compensate
figure
boxchart(earthquakes.Month,earthquakes.EarthquakeMagnitude,'BoxWidth',0.05)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Seismology에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by