2
我想使用rotate_deg_around()函數在其左下角旋轉matplotlib矩形修補程序對象。但是,該補丁總是圍繞某個不同的點旋轉。任何想法爲什麼rotate_deg_around()函數沒有產生期望的結果?無法使用rotate_deg_around()旋轉關於特定點的matplotlib修補程序對象
我的代碼如下:
f,(ax1) = plt.subplots(1,1,figsize=(6,6))
f.subplots_adjust(hspace=0,wspace=0)
ts = ax1.transData
coords = ts.transform([1,1])
tr = mpl.transforms.Affine2D().rotate_deg_around(coords[0], coords[1], 10)
t = ts + tr
rec0 = patches.Rectangle((1,1),3,2,linewidth=1,edgecolor='r',facecolor='none')
ax1.add_patch(rec0)
#Rotated rectangle patch
rect1 = patches.Rectangle((1,1),3,2,linewidth=1,edgecolor='b',facecolor='none',transform=t)
ax1.add_patch(rect1)
# Rectangles lower left corner
plt.plot([1], [1], marker='o', markersize=3, color="green")
plt.grid(True)
ax1.set_xlim(0,6)
ax1.set_ylim(-1,4)
導致如下圖所示:
我按照 Unable to rotate a matplotlib patch object about a specific point using rotate_around()
任何幫助深表感謝。
這是有道理的,現在,它的工作原理(我的身材現在是相同爲t他是你在這裏提供的)。謝謝你的時間。 –
我更新了答案,因爲來自其他問題的解決方案實際上並不理想。 – ImportanceOfBeingErnest
更好!再次感謝。 –