I want to plot 2 bars side by side each other but i keep getting an error:
ValueError: Cannot shift with no freq
This error occurred when i set my x in the axes.bar to be x-width.
Here is my code:
df.date_1 = pd.to_datetime(df.date_1)
df_percent.date_1 = pd.to_datetime(df_percent.date_1)
df = df.set_index(df['date_1']).sort_index()
df_percent = df_percent.set_index(['date_1']).sort_index()
df_percent = df_percent.reindex(df.index).fillna(0)
fig, ax = plt.subplots(figsize=(10, 8))
ax.plot( df.index, df.line1,label='line1', c='b')
ax.plot( df.index, df.line2,label='line2', c='r')
ax2=ax.twinx()
#i added the x-10 to the bar chart that i want to shift to the right
ax2.bar(df_percent.index, df_after, width=10, alpha=0.1, color='r', label='after')
ax2.bar(df_percent.index-10, df_before, width=10, alpha=0.1, color='g', label='before')
If i do a stacked bar chart it works fine.
date_1 line1 line2
date_1
2014-06-01 2014-06-01 65 66
2014-07-01 2014-07-01 68 70
2014-08-01 2014-08-01 62 65
2014-09-01 2014-09-01 62 76
2014-10-01 2014-10-01 63 66
2014-11-01 2014-11-01 79 80
2014-12-01 2014-12-01 80 50
2015-02-01 2015-02-01 70 72
2015-03-01 2015-03-01 67 67
2015-04-01 2015-04-01 69 60
2015-05-01 2015-05-01 66 83
date_1 before after
date_1
2014-06-01 2014-06-01 19.80 15.37
2014-07-01 2014-07-01 62.82 44.87
2014-08-01 2014-08-01 36.70 27.52
2014-09-01 2014-09-01 56.18 34.27
2014-10-01 2014-10-01 16.31 10.95
2014-11-01 2014-11-01 32.35 14.71
2014-12-01 2014-12-01 53.33 26.67
2015-02-01 2015-02-01 44.44 17.78
2015-03-01 2015-03-01 23.08 23.08
2015-04-01 2015-04-01 36.84 15.79
2015-05-01 2015-05-01 46.58 13.70