0

I've aggregated values by month to display as a bar chart using Pandas TimeGrouper:

fig, ax = plt.subplots(figsize=(15,10))
df = pd.read_excel('example.xlsx',index_col='Date')
g = df.groupby(pd.TimeGrouper("M"))
g[['Money Out','Money in']].sum().plot(kind='bar',ax=ax) 

Which gives me this output:

bar chart

But I also want to display the raw data on this same chart as a line series, for example:

df['Balance'].plot(ax=ax)

To give this:

series

However, when I plot both together, only the bar chart shows, even though the x axis appears to me to be dates that should be compatible.

EDIT Here is an example of the data when printed. enter image description here

Dùn Caan
  • 111
  • 4
  • Can you add an example? For instance `print(df.head(20))`. – IanS May 27 '16 at 07:40
  • @IanS I've added printed output now, let me know if you want anything else. Cheers – Dùn Caan May 27 '16 at 08:07
  • It would be much better if you copied the result as text. See [general advice here](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – IanS May 27 '16 at 08:16
  • 1
    This is a [known issue when the x-axis is a DateTimeIndex](https://github.com/pydata/pandas/issues/10761#issuecomment-128807571). The link points you to a comment that has a workaround. – IanS May 27 '16 at 08:36
  • Last comment: I would recommend plotting the balance as `df.Balance.groupby(pd.TimeGrouper('M')).nth(-1)`, which is the last balance of the month. – IanS May 27 '16 at 08:44
  • @IanS thanks for the tips and pointing out that existing issue - I hadn't seen that yet. Cheers. – Dùn Caan May 27 '16 at 11:38

0 Answers0