在现有的 matplotlib 轴上绘图

默认情况下,plot() 每次调用时都会创建一个新图形。可以通过传递 ax 参数在现有轴上绘图。

plt.figure()  # create a new figure
ax = plt.subplot(121)  # create the left-side subplot
df1.plot(ax=ax)  # plot df1 on that subplot
ax = plt.subplot(122)  # create the right-side subplot
df2.plot(ax=ax)  # and plot df2 there
plt.show()  # show the plot