vexato
vexato

Reputation: 25

I get an error when I use boxplot from pandas with subplots

For example if I have this dataframe and plot a density plot:

df = pd.DataFrame(np.random.randn(6,6))
df.plot(kind='density', subplots=True, layout=(3,2), sharex=False, sharey=False,
fontsize=1)
pyplot.show()

It yields

Show image

The thing is that if I try to do the same with boxplot I get and error:

df.plot(kind='box', subplots=True, layout=(3,2), sharex=False, sharey=False,
fontsize=1)
pyplot.show()

I get the following error:

IndexError: index 0 is out of bounds for axis 0 with size 0

Thanks

Upvotes: 2

Views: 976

Answers (2)

Quang Hoang
Quang Hoang

Reputation: 150745

Seems like there's a bug for integer columns. This works:

df = pd.DataFrame(np.random.randn(6,6))
df.columns=list('abcdef')

df.plot.box(subplots=True, layout=(3,2))

Output:

enter image description here

Or change the column type to str:

(df.rename(columns=lambda x: str(x))
   .plot.box(subplots=True, layout=(3,2))
)

Output:

enter image description here

Upvotes: 2

Kalron
Kalron

Reputation: 884

Are you sure thats the way to use boxplot

See this

I think it would be like this so

df.boxplot(by=0,layout=(3,2))

Upvotes: 0

Related Questions