0

I was trying to plots near each other, however this results in error:

sns.set_style('darkgrid')
f , axes =plt.subplots(1, 2, figsize=(15,15))

sns.boxplot(data=df, x='Month', y='Price', ax=axes[0,0])
sns.boxplot(data=df, x='Year', y='Price', ax=axes[0,1])

Here is the error:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/tmp/ipykernel_33/3036328835.py in <module>
      2 f , axes =plt.subplots(1, 2, figsize=(15,15))
      3 
----> 4 sns.boxplot(data=df, x='Month', y='Price', ax=axes[0,0])
      5 sns.boxplot(data=df, x='Year', y='Price', ax=axes[0,1])

IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
1
  • Can you show df? Commented Jan 10, 2022 at 11:48

1 Answer 1

5

axes is 1-dimensional, but you are trying to access as 2-dimensional. axes[0] and axes[1] are what you want, or call subplots(1, 2, squeeze=False)

https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html

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.