python - Pandas 情节,结合两个情节

标签 python pandas matplotlib

目前我在 2x2 子图中绘制了 3 个图。它看起来像这样:

fig, axes = plt.subplots(nrows=2, ncols=2)
df1.plot('type_of_plot', ax=axes[0, 0]);
df2.plot('type_of_plot', ax=axes[0, 1]);
df3.plot('type_of_plot', ax=axes[1, 0]);

第 4 个子图是空的,我希望第 3 个子图占据整个最后一行。

我为第三个子图尝试了各种轴组合。像 axes[1]axes[1:]axes[1,:]。但一切都会导致错误。

那么我怎样才能达到我想要的呢?

最佳答案

你可以这样做:

import matplotlib.pyplot as plt

fig=plt.figure()
a=fig.add_axes((0.05,0.05,0.4,0.4)) # number here are coordinate (left,bottom,width,height)
b=fig.add_axes((0.05,0.5,0.4,0.4))
c=fig.add_axes((0.5,0.05,0.4,0.85))

df1.plot('type_of_plot', ax=a);
df2.plot('type_of_plot', ax=b);
df3.plot('type_of_plot', ax=c);

plt.show()

另见 documentation of add_axes

我给你的rect坐标可读性不是很好,但你可以很容易地调整它。

编辑:这是我得到的:enter image description here

关于python - Pandas 情节,结合两个情节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38989178/

相关文章:

php - 无法通过 PHP 调用 python 脚本

python - 命令 $python3 manage.py migrate 出错

python - Matplotlib交互环境不起作用

python - 如何在Python中启用辅助轴(twiny)的共享

Python cql 库无法使用查询替换更新 bool 列

python - 更Pythonic的方式来替换字符串中的关键字?

python - 如何仅对数据框中的某些行进行 KNN 测试?

python - 匹配数据帧之间的部分表达式

mysql - 如何从mysql连接下载数据

python - 使 matplotlib 按钮小部件在按下时启动,而不是在释放时启动