how to rotate the rectangle in matplotlib patch?

时间:2017-06-09 12:58:27

标签: python matplotlib

I am drawing rotated rectangle using matplotlib but I don't know how to adjust the angle?

rect = patches.Rectangle((int(arr[2])-0.5*int(arr[4]),int(arr[3])-0.5*int(arr[5])), int(arr[4]),int(arr[5]),
                        fill=False,
                        edgecolor='g', linewidth=1)
t = matplotlib.transforms.Affine2D().rotate_around(float(arr[2]), float(arr[3]),\
                float(arr[6])*180/np.pi)

rect.set_transform(t + plt.gca().transData)

plt.gca().add_patch(rect)

1 10 3308 261 21 10 -88.363423
this is the data of one car

but the rectangel don't fit it.

description

1 个答案:

答案 0 :(得分:0)

似乎旋转角度应为-88度。

负角度将顺时针旋转。 .rotate_around期待它的角色论证在于辐射。

您正在使用float(arr[6])*180/np.pi,它会将辐射转换为度数,但由于您已经拥有度数角度,因此没有多大意义。

改为使用

float(arr[6])*np.pi/180.

np.deg2rad(float(arr[6]))

enter image description here