Sal*_*ali 5 python matplotlib pandas
目前,我在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]);
Run Code Online (Sandbox Code Playgroud)
第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()
Run Code Online (Sandbox Code Playgroud)
另请参阅add_axes 的文档
我给你的坐标rect不太可读,但你可以轻松调整它。