2016-10-19 15 views
0

嗨,我在ipad上使用Pythonista 3:0。作为初学者,我下载了一些例子来试用。他们工作了一段时间,但现在当我尝试运行它们时,没有任何反应。原始Phthonista安装中的所有示例程序都能很好地工作。Pythonista用户启动的程序不运行

例如,这是行不通的。当我按下三角形时没有任何反应。 感谢

# -*- coding: utf-8 -*-from mpl_toolkits.mplot3d import Axes3D 
import matplotlib.pyplot as plt 
import numpy as np 
from itertools import product, combinations 
fig = plt.figure() 
ax = fig.gca(projection='3d') 
ax.set_aspect("equal") 

#draw cube 
r = [-1, 1] 
for s, e in combinations(np.array(list(product(r,r,r))), 2): 
    if np.sum(np.abs(s-e)) == r[1]-r[0]: 
     ax.plot3D(*zip(s,e), color="b") 

# draw sphere 
u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j] 
x=np.cos(u)*np.sin(v) 
y=np.sin(u)*np.sin(v) 
z=np.cos(v) 
ax.plot_wireframe(x, y, z, color="r") 

#draw a point 
ax.scatter([0],[0],[0],color="g",s=100) 

#draw a vector 
from matplotlib.patches import FancyArrowPatch 
from mpl_toolkits.mplot3d import proj3d 

class Arrow3D(FancyArrowPatch): 
    def __init__(self, xs, ys, zs, *args, **kwargs): 
     FancyArrowPatch.__init__(self, (0,0), (0,0), *args, **kwargs) 
     self._verts3d = xs, ys, zs 

    def draw(self, renderer): 
     xs3d, ys3d, zs3d = self._verts3d 
     xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M) 
     self.set_positions((xs[0],ys[0]),(xs[1],ys[1])) 
     FancyArrowPatch.draw(self, renderer) 

a = Arrow3D([0,1],[0,1],[0,1], mutation_scale=20, lw=1, arrowstyle="-|>", color="k") 
ax.add_artist(a) 
plt.show() 

回答

0

在我看来,Pythonista的matplotlib可能从0.9倍到1.x的升级你应该使用不同的语法如下。

# -*- coding: utf-8 -*- 
import matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import Axes3D 
import numpy as np 
from itertools import product, combinations 

fig = plt.figure() 
ax = Axes3D(fig) ## it's different now. 
ax.set_aspect("equal") 
+0

谢谢你的Jak辽 - 我取代你好心提供的代码,但可惜什么也没有发生不运行 – Valavel

0

您使用的应用程序商店版本的pythonista 3?或测试版? 您的代码在测试中对我的工作非常好(如果我取消注释导入Axes3D行,否则我会得到关于无效投影的错误)

我相信app store版本可能与python 3版本matplotlib(例如,使用自定义后端导致崩溃)。尝试使用python 2.7解释器来查看是否有效。

而且,一个共同的问题有些人是他们在现场包或同一文件夹中的脚本来替换一些需要导入创建的.py文件。检查您的网站包,并确保您删除或重命名任何名为numpy或matplotlib的脚本或文件夹,然后强制退出pythonista。

最后,你可以尝试运行脚本线,看是否有问题的地方。例如通过长按来设置断点,然后当您按下播放按钮时,它会询问您是否要使用调试器。这将让你检查plt是私人路径中的matplotlib.pyplot包。

你可能在pythonista社区论坛或松懈频道上也可能有更好的pythonista问题。

+0

对不起jonB我感谢您在本页面 - 但没有连接到您的罚款答案 – Valavel

相关问题