在現有的 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