使用plotu()函数围绕一个特定于plotu的点旋转plotu()。但是,面片始终围绕原点旋转。我不知道如何确保面片对象围绕特定点旋转。在
代码如下:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib as mpl
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlim(-0.05,1);ax.set_ylim(-0.05,1);
grid('on');
#Rotate rectangle patch object
ts = ax.transData
tr = mpl.transforms.Affine2D().rotate_deg_around(0.2,0.5,10)
t= ts + tr
rec0 = patches.Rectangle((0.2,0.5),0.25,0.2,alpha=0.5)
ax.add_patch(rec0)
#Rotated rectangle patch
rect1 = patches.Rectangle((0.2,0.5),0.25,0.2,color='blue',alpha=0.5,transform=t)
ax.add_patch(rect1);
#The (desired) point of rotation
ax.scatter([0.0,0.2],[0.0,0.5],c=['g','r'],zorder=10)
txt = ax.annotate('Desired point of rotation',xy=(0.2,0.5),fontsize=16,\
xytext=(0.25,0.35),arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=-.2"))
txt2 = ax.annotate('Actual point of rotation',xy=(0.0,0.0),fontsize=16,\
xytext=(0.15,0.15),arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=.2"))
plt.show()
下面是上述代码的输出:
我也试着做翻译,围绕着_的原点旋转,然后把你翻译回来。然而,翻译转换也不起作用。任何简单翻译的帮助/例子也会非常有用。在
谢谢。在
@David Zwicker,谢谢你给我指出了正确的方向。以下代码在交互模式下正常工作(即可以重新调整图形窗口的大小),可以独立执行,也可以在ipythonqtconsole环境中执行。参见下面的嵌入图。然而,它仍然不能在ipythonwebnotebook环境中工作!任何关于这方面的帮助/想法都会很好。谢谢您。在
以下是上述代码的一些示例:
在代码中使用savefig()函数保存图像:
使用导航面板中的“保存”按钮保存的图像:
重新调整大小后使用导航面板中的“保存”按钮保存的图像:
旋转的坐标不是数据坐标。你必须先改变他们,也就是说
编辑:
显然,代码只适用于交互式显示,但在调整窗口大小或保存图形时不起作用。比较这两幅图像:
看来,在保存时,Ipython会将层更改为外部。旋转矩形的变换取决于显示坐标,在缩小或更改图层时可以更改,缩放在交互窗口中。在
我们可以在数据坐标系中旋转矩形。见Rotating a figure (patch) and applying colors in python
当我们需要的时候”轴集面('equal')”以避免旋转矩形变形。在
相关问题 更多 >
编程相关推荐