繁体   English   中英

python pandas DataFrame子列中的行和列

[英]python pandas DataFrame subplot in columns and rows

我想从数据4列DataFrame生成一个子图,分为2行和2列

df =pd.DataFrame(np.random.randn(6,4),index=pd.date_range('1/1/2000',periods=6, freq='1h'))

但是下面将给出4行和1列图

 df.plot(use_index=False, title=f, subplots=True, sharey=True, figsize=(8, 6))

谢谢。

cplcloud的答案有效,但是下面的代码将为您提供更多结构,以便您可以在不需要循环时开始配置更多。

fig, axes = plt.subplots(nrows=2, ncols=2)
fig.set_figheight(6)
fig.set_figwidth(8)
df[0].plot(ax=axes[0,0], style='r', label='Series'); axes[0,0].set_title(0)
df[1].plot(ax=axes[0,1]); axes[0,1].set_title(1)
df[2].plot(ax=axes[1,0]); axes[1,0].set_title(2)
df[3].plot(ax=axes[1,1]); axes[1,1].set_title(3)
fig.tight_layout()

在轴0上添加了一些示例,以说明如何进一步配置它。

在当前版本的Pandas中, DataFrame.plot为此目的提供了layout关键字。

df.plot(subplots=True, layout=(2,2), ...)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM