2

with a dataframe df in Pandas, I am trying to plot histograms on the same page filtering by 3 different variables; the intended outcome is histograms of the values for each of the three types. The following code works for me as PLOTs, but when I change to HISTs, they all stack on top of each other. Any suggestions?

plt.figure(1)

plt.subplot(311)
df[df.Type == 'Type1'].values.plot()

plt.subplot(312)
df[df.Type == 'Type2'].values.plot()

plt.subplot(313)
df[df.Type == 'Type3'].values.plot()

plt.savefig('output.pdf')

Is this a bug in Pandas or are plot and hist not interchangable?

Thanks in advance

user574435
  • 143
  • 1
  • 10

1 Answers1

2

Plot and hist aren't interchangabe: hist is its own DataFrame and Series methods. You might be able to force the plots to be independent by passing in an ax keyword. So

fig = plt.figure()
ax1 = fig.add_subplot(3,1,1)
df[df.Type == 'Type1'].values.hist(ax=ax1)
....
story645
  • 566
  • 3
  • 13