简体   繁体   中英

Draw subplots boxplot using python

I want to draw two parallel box plot in together. For that I used sub plots function in python, below code I used for the that process, but I couldn't get good out put from the code, because its already draw addition two empty graphs, how I remove these empty graphs from the output? Please give ideas for that?

f, axes = plt.subplots(2,2,figsize = (14,10))
sns.boxplot(x='Heating QC',y='SalePrice',hue='Central Air',  data=df ,ax=axes[0,0])
sns.boxplot(x='Heating',y='SalePrice',hue='Central Air',  data=df ,ax=axes[0,1])

out put

磷

After changes got below outputs

IndexError                                Traceback (most recent call last)
<ipython-input-543-7dfa6ebf0390> in <module>
      1 f, axes = plt.subplots(1,2,figsize = (14,10))
----> 2 sns.boxplot(x='Heating QC',y='SalePrice',hue='Central Air',  data=df ,ax=axes[0,0])
      3 sns.boxplot(x='Heating',y='SalePrice',hue='Central Air',  data=df ,ax=axes[0,1])

IndexError: too many indices for array

在此处输入图片说明

Just create two plots, in which case axes will be a list of 2 elements and use those plot.

Refer the documentation .

f, axes = plt.subplots(2, figsize = (14,10))
sns.boxplot(x='Heating QC',y='SalePrice',hue='Central Air',  data=df, ax=axes[0])
sns.boxplot(x='Heating',y='SalePrice',hue='Central Air',  data=df, ax=axes[1])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM