Boxplot with double y-axis

조회 수: 28 (최근 30일)
sunny kant
sunny kant 2022년 8월 24일
답변: sunny kant 2022년 8월 24일
Hello All, I want to plot a boxplot with a double y-axis (reference figure is attached). Actually, I have two sets of variables. One variable value will display on the left side and another variable value will display on the right of the y-axis.

채택된 답변

Aditya
Aditya 2022년 8월 24일
편집: Aditya 2022년 8월 24일
MATLAB doesn't support drawing two boxplots as you are suggesting. But, you can use a work around.
The idea is to create empty box plots.
load carsmall
yyaxis left
boxplot([Acceleration nan(100,1)])
yyaxis right
boxplot([nan(100,1) Horsepower])
You can see that [Acceleration nan(100,1)] creates a 100x2 matrix with second column as nan.
  • When I use boxplot for left axis, it plots two curves at x-location 1 and 2 for each column. As the second column is nans, second boxplot is empty.
  • Now, for second plot, I want location-1 to be empty (as I already have plotted acceleration on that), so I use [nan(100,1) Horsepower], which will draw Horsepower at x-location 2.
For your refereimage, you will need to do something like this
yyaxis left
boxplot([l1 nan(100,1) l2 nan(100,1) l3 nan(100,1)])
yyaxis right
boxplot([nan(100,1) r1 nan(100,1) r2 nan(100,1) r3])
This is not what you are looking for but I think closest:

추가 답변 (4개)

Aditya
Aditya 2022년 8월 24일
편집: Aditya 2022년 8월 24일
Hi,
You can use the yyaxis command.
The key idea is to activate the axis that you want to plot. Suppose I have two ys : y1 and y2, I want to plot y1 on the left side and y2 on the right side, I can do as shown here:
yyaxis left
plot(x,y1);
yyaxis right
plot(x,y2);
You can read more about it at the example shown here.

sunny kant
sunny kant 2022년 8월 24일
Thank you Aditya for your reply. This will work for the plot command. I am applying for the boxplot, it is not working.
  댓글 수: 1
Aditya
Aditya 2022년 8월 24일
편집: Aditya 2022년 8월 24일
I think it is working as intended, as there are two boxplots at the same 'x'.
A simple example is here
load carsmall
yyaxis left
boxplot(Acceleration)
yyaxis right
boxplot(Horsepower)
What you are looking for is a no superposition.

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


sunny kant
sunny kant 2022년 8월 24일
Aditya, I have also tried this, but two variables (means two box) go inside each other. I want to separate it (image attached for your reference) because it can be two separate boxes for two variables.

sunny kant
sunny kant 2022년 8월 24일
Thank you Aditya, it worked for me.

카테고리

Help CenterFile Exchange에서 Exploration and Visualization에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by