2013-02-15 171 views
11

我想产生从数据的副区4列数据帧分成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)) 

谢谢。

+4

应手动,'进口matplotlib.pyplot为plt',然后像'因为我做的DF:plt.subplot(2,2,I + 1); plt.plot(DF [ i]);' – 2013-02-15 06:27:59

+1

@ tesla1060我想大熊猫可以允许某种'figshape'参数... – 2013-06-07 21:54:08

回答

9

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上添加了一些示例,显示如何进一步配置它。

7

在当前版本的熊猫中,DataFrame.plot功能layout关键字为此目的。

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