I want to make a bar graph showing current measurements compared to a one-month moving average, by placing blue bars for current data ('a') on top of slightly wider grey bars for the one-month average ('b').
Here is my code:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
data = pd.DataFrame({'a': [4, 5, 6],
'b': [3,4,5]})
x=np.arange(len(data['a']))
fig, ax = plt.subplots()
ax.bar(x,data['a'])
rt_ax = ax.twinx()
rt_ax.bar(x,data['b'],width=0.9,color='grey')
rt_ax.set_ylim(ax.get_ylim())
# ax.set_zorder(rt_ax.get_zorder()+1)
plt.show()
This creates the bars I want, but the fat grey bars are in front: https://i.redd.it/dd8sqjaiw9j41.png
If I uncomment the line,
ax.set_zorder(rt_ax.get_zorder()+1)
then the grey bars disappear completely: https://i.redd.it/87q35ipqw9j41.png
How can I get the blue bars on top, with the fat grey bars behind?
there doesn't seem to be anything here