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 Center および File ExchangeExploration and Visualization についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by