[英]How to "stack" matplotlib figures
我按以下一般方式創建了 3 個 matplotlib 圖:
fig1, ax = plt.subplots(1,2, figsize=(20,6))
ax[0].scatter(...)
...
ax[1].plot(...)
ax[1].axhline(...)
fig2, ax = plt.subplots(1,2, figsize=(20,6))
ax[0].scatter(...)
...
ax[1].plot(...)
ax[1].axhline(...)
fig3, ax = plt.subplots(1,2, figsize=(20,6))
ax[0].scatter(...)
...
ax[1].plot(...)
ax[1].axhline(...)
我想將fig1
、 fig2
和fig3
“組合”成一個“圖形” object ,我可以將其命名為 plot ,例如 3x2 圖形。
創建一個帶有subplots
圖的圖形:
fig, axs = plt.subplots(3, 2, figsize=(20, 6))
axs[0, 0].scatter(...)
axs[0, 1].plot(...)
axs[0, 1].axhline(...)
axs[1, 0].scatter(...)
axs[1, 1].plot(...)
axs[1, 1].axhline(...)
axs[2, 0].scatter(...)
axs[2, 1].plot(...)
axs[2, 1].axhline(...)
這里axs
是一個 3x2 數組:
print(axs)
# array([[<AxesSubplot:>, <AxesSubplot:>],
# [<AxesSubplot:>, <AxesSubplot:>],
# [<AxesSubplot:>, <AxesSubplot:>]], dtype=object)
因此,如果願意,您也可以將其解壓縮:
成 3 行軸(每個 1x2)
fig, (ax1, ax2, ax3) = plt.subplots(3, 2)
分成 6 個單獨的軸
fig, ((ax11, ax12), (ax21, ax22), (ax31, ax33)) = plt.subplots(3, 2)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.