我創(chuàng)建了一個(gè) (2x3) 子圖并強(qiáng)制它們constrained_layout=True使用下面的代碼。我想隱藏 ax03 并在該區(qū)域創(chuàng)建其他圖形。出于對(duì)齊的目的,我曾經(jīng)ax.get_position獲取過(guò) ax03 的軸位置,并使用它add_axes()來(lái)制作一個(gè)新的軸。但似乎它沒(méi)有按預(yù)期對(duì)齊。根據(jù)我的觀察,get_position()在布局重新安排之前返回軸的位置。注意:如果我分兩部分執(zhí)行代碼,那么我當(dāng)然可以得到位置。我想在一次執(zhí)行中實(shí)現(xiàn)它。import matploltib.pyplot as plt# Section 1fig, axes = plt.subplots(2, 3, figsize=(7.2, 7.2/1.68), constrained_layout=True)axes = axes.ravel()ax01 = axes[0]ax02 = axes[1]ax03 = axes[2]ax11 = axes[3]ax12 = axes[4]ax13 = axes[5]# Section 2pos = ax03.get_position() # get the original positionwidth = pos.x1 - pos.x0height = pos.y1 - pos.y0print(ax03.get_position())ax = fig.add_axes([pos.x0, pos.y0, width, height])print(ax.get_position()) # it seems the position of ax is the postion before constrained is applied.這是同時(shí)執(zhí)行第 1 節(jié)和第 2 節(jié)時(shí)得到的結(jié)果。職位信息:Bbox (x0 = 0.6720588235294118, y0 = 0.53, x1 = 0.9000000000000001, y1 = 0.88) Bbox (x0 = 0.6720588235290588235290 = 0.6720588235290 =.010.0010.08).080.08
如何在matplotlib約束布局模式下檢索軸的真實(shí)位置
明月笑刀無(wú)情
2021-11-02 15:08:37