我正在尝试使用Pandas matplotlib API在同一张图上绘制条形图和折线图。然而,这并不是很顺利。我正在使用twinx(),这似乎是普遍接受的完成此任务的方法。
请注意,这是在Jupyter笔记本中完成的,其中的绘图以内联方式显示。感谢您的帮助!
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()发布于 2015-11-13 03:56:14
什么地方出问题了?您的代码看起来运行良好。
%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()

https://stackoverflow.com/questions/33678435
复制相似问题