我想将 pandas 数据框的三列绘制为 2x2 子图布局:
rand=np.random.random((12,6))
df=pd.DataFrame(columns=['a','b','c','d','e','f'],data=rand)
ax=df.loc[:,'a':'c'].plot(subplots=True,layout=(2,2))
Run Code Online (Sandbox Code Playgroud)
这给了我想要的结果(右下角有一个空图)。但是,如果我尝试使用以下方法向所有这些子图添加另一列
df.loc[:,'d':'f'].plot(subplots=True,ax=ax)
Run Code Online (Sandbox Code Playgroud)
出现以下错误:
ValueError: The number of passed axes must be 3, the same as the output plot
Run Code Online (Sandbox Code Playgroud)
有没有办法解决这个问题,而无需重新安排子图的布局?