我无法在Spyder IDE中运行/使用Mayavi库.我已经描述了下面的问题.任何帮助都将非常有用.(非常感谢你提前.)
重现问题的步骤:
from numpy import sin, cos, mgrid
import mayavi.mlab as mmlab
def f(x,y):
return sin(x + y) + sin(2*x - y) + cos(3*x + 4*y)
x,y = mgrid[-7.:7.05:0.01, -5.:5.05:0.05]
z = f(x,y)
s = mmlab.contour_surf(x,y,z)
mmlab.show()
Run Code Online (Sandbox Code Playgroud)
预期输出和错误:
预期输出:带有数字的Mayavi数字窗口.我所看到的是:在控制台窗口中出现以下值错误(我包括完整的消息序列以便显式):
--------------------------错误信息的开头------------------
Traceback (most recent call last):
File "C:\PROGRAMSANDEXPERIMENTS\PYTHON\MayaviScripts\Learning\testMayavi.py", line 2, in <module>
import mayavi.mlab as mmlab
File "C:\Python27\lib\site-packages\mayavi\mlab.py", line 27, in <module>
from mayavi.tools.camera import view, roll, yaw, pitch, move
File "C:\Python27\lib\site-packages\mayavi\tools\camera.py", line 25, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 rotate_around() 和 rotate_deg_around() 函数围绕特定点旋转 matplotlib 矩形补丁对象。但是,补丁始终围绕原点旋转。我不确定如何确保补丁对象围绕特定点旋转。
这里的代码如下:
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()
Run Code Online (Sandbox Code Playgroud)
下面是上面代码的输出:

我也尝试过做 …