相关疑难解决方法(0)

无法使用rotate_deg_around()围绕特定点旋转matplotlib patch对象

我想使用rotate_deg_around()函数围绕其左下角旋转matplotlib矩形面片对象。然而,补丁总是围绕某个不同的点旋转。知道为什么rotate_deg_around()函数没有产生期望的结果吗?

我的代码如下:

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)
Run Code Online (Sandbox Code Playgroud)

得到下图:

在此输入图像描述

我遵循 Unable to spin a matplotlib patch object about a certain point usingrotate_around( )

任何帮助深表感谢。

python matplotlib

4
推荐指数
1
解决办法
2279
查看次数

标签 统计

matplotlib ×1

python ×1