[英]add_axes to pyplot figure attaches new axis to old axis with same position
當我嘗試在原先放置另一個軸的同一位置上使用fig.add_axes將軸添加到pyplot圖形中時,pyplot只是引用了舊軸。
我有一個要求在哪里制作數字,然后可以添加軸。 根據要求,添加不同的軸。
我嘗試將ax.set_position的“哪個”參數設置為“兩者”,“活動”和“原始”,但是沒有一個參數。
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_axes([0.07, 0.1, 0.88, 0.2])
ax1.set_position([0.07, 0.3, 0.88, 0.2], which='active')
ax2 = fig.add_axes([0.07, 0.1, 0.88, 0.2])
ax2.set_position([0.07, 0.3, 0.88, 0.5])
# When trying to set position of either figure it simply moves them both
# as ax2 is a reference to ax1
ax1.set_position([0.07, 0.1, 0.88, 0.2])
我如何獲得它,例如ax2是未引用ax1的獨立對象?
我自己找到了一個答案-這是萬一其他人都面臨類似問題的情況。
該問題將在下一版的matplotlib中修復,但與此同時,可以通過為每個軸指定標簽來繞過此問題。
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_axes([0.07, 0.1, 0.88, 0.2], label='no_1')
ax1.set_position([0.07, 0.3, 0.88, 0.2], which='both')
ax2 = fig.add_axes([0.07, 0.1, 0.88, 0.2], projection=None)
ax2.set_position([0.07, 0.1, 0.88, 0.5], label='no_2')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.