I'm attempting to have a bar plot and line plot on the same figure using Pandas matplotlib API. However, it is not going very well. I am using twinx() which seems to be the generally accepted way of accomplishing this.
Note that this is done in a Jupyter notebook, with the plot being shown inline. Thank you for the assistance!
fig0, ax0 = matplotlib.pyplot.subplots()
ax1 = ax0.twinx()
trend_df_hours.plot(kind='bar', stacked=True, color=color_list, ax=ax0)
trend_df_qty.plot(kind='line', secondary_y=True, ax=ax1)
matplotlib.pyplot.show()
matplotlib.pyplot.close()
What seems to be the problem? Your code appears to work fine.
%matplotlib inline
from matplotlib import pyplot as plt
trend_df_hours = pd.Series(np.random.rand(10))
trend_df_qty = pd.Series(np.random.rand(10))
fig0, ax0 = plt.subplots()
ax1 = ax0.twinx()
trend_df_hours.plot(kind='bar', stacked=True, ax=ax0)
trend_df_qty.plot(kind='line', secondary_y=True, ax=ax1)
plt.show()
plt.close()

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With