I am plotting different columns of a year of hourly data from a Pandas dataframe. I have written the following function to plot:
def plotResults(dfA):
fig, (ax1,ax2) = plt.subplots(2, sharex=True, sharey=False)
ax1.plot(dfA.index, dfA['LP1'], color='blue',alpha=0.7, label='LP1')
ax1.bar(dfA.index, dfA['b'], color='green',alpha=0.1, rwidth=1, label='b')
ax1.bar(dfA.index, dfA['p'].fillna(0), color='red',alpha=0.1, rwidth=1, label='p', bottom=dfA['b'])
ax1.legend(loc='best')
ax2.plot(dfA.index, dfA['Residual'], color='red',alpha=0.7, label='LP1')
ax2.legend(loc='best')
plt.show()
The bars for the bar charts are overlapping for some reason that I do not understand. I have been trying with width = 1.0/(len(dfA.index))
but then the bars get extremely narrow.
How can I set up the bars so they do not overlap and cover one hour (which is the periodicity of dfA)?
There should be gaps between the red bars in the upper graph. They only have values for some hours.