um8*_*8ra 2 python plot matplotlib pandas
我正在尝试使用 Pandas matplotlib API 在同一个图形上绘制条形图和线图。然而,进展并不顺利。我正在使用 twinx() 这似乎是实现这一目标的普遍接受的方式。
请注意,这是在 Jupyter Notebook 中完成的,绘图显示为内联。感谢您的帮助!
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()
Run Code Online (Sandbox Code Playgroud)
似乎是什么问题?您的代码似乎工作正常。
%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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5843 次 |
| 最近记录: |