0

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

p

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

enter image description here

4
  • 1
    plt.subplots(2,2) creates a 2x2 grid of subplots, that's why you've got 4 plots showing.You need to change it to to a 1,2 or 2,1 as you see fit. matplotlib.org/api/_as_gen/matplotlib.pyplot.subplots.html Commented Feb 1, 2020 at 8:07
  • @DavidBuck yes I changed plt.subplots(1,2) then there no any outputs, only give error massage and empty two graph. I add that out put and error massage in question section. Commented Feb 1, 2020 at 9:20
  • 1
    Your ax now need to change to just axes[0] and axes[1] as you only have a one dimensional array of subplots. That's covered here: stackoverflow.com/questions/54170394/… Commented Feb 1, 2020 at 9:38
  • @DavidBuck now code is working properly thanks your support. Commented Feb 1, 2020 at 11:09

1 Answer 1

1

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])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.