1

Running into an odd problem. I'm trying to plot a dual line graph time series, with the difference between those graphs shown as bars in the same graph.

ax = dfx['diff'].plot(kind='bar')
dfx['p1','p2'].plot(ax=ax,kind='line)

So far, so good, this works and gives me the visual I'd like but because the index is made up of unicode date strings, the x axis is a jumbled mess. So I go back and convert the index into timestamps:

dfx['Date'] = pd.to_datetime(pd.Series(dfx['Date']))

I then reset this new column as the index. Problem is, now when I try to plot it, the x axis is perfect, formatted nicely, but the "diff" bars completely disappear, yet it still shows up in the legend. Feels like whack-a-mole...one problem solved, another appears ;)

Thanks for your help!

Edit: After some testing, I've found that if I show the diff as a line, it's fine, which makes me think it's a problem with continuous vs discrete plotting. I think it's getting confused when attempting to show bar graphs on a continuous timestamp range...but I can't be the only person who's wanted to plot lines and bars on the same graph in pandas...

David Yang
  • 2,101
  • 13
  • 28
  • 46

0 Answers0