【发布时间】:2021-05-30 07:25:03
【问题描述】:
在结合 Matplotlib 和 Pandas 进行绘图时,我试图更好地了解图形、轴和 plt 是如何组合在一起的。接受的answer here 帮助我以我通过这一行理解的面向对象的方式连接了 Matplotlib 和 Pandas:
fig, ax = plt.suplots()
df.plot(ax=ax)
但随着我的深入,answer here 让我失望了。具体来说,我仍然有需要直接从 plt 调用的方法,这些方法不适用于图形或轴。示例:
fig, ax = plt.subplots()
df[['realgdp','trend']]["2000-03-31":].plot(figsize=(8,8), ax=ax)
ax.set_title('Real GDP & Trend')
ax.set_ylabel('Readl GDP')
plt.xticks(rotation=45)
如果我尝试从 ax 或 fig 中调用 xticks(rotation=45),则会收到一个错误,即 ax 和 fig 都没有 xticks 方法。我上面的解决方案有效,但我不明白为什么。
当我输入plt.xticks(rotations=45) 时,该信息会发送到哪里?为什么answer here 中的评论“当您使用模块 pyplot 上可用的功能时,您正在绘制到 '当前图形' 和 '当前轴'”在这种情况下不适用?为什么要直接取消plt?
【问题讨论】:
标签: python pandas matplotlib