所以我想創建一個3D繪圖和我寫的代碼3D圖是:與numpy的蟒蛇
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
a=[1,5,10]
x=list(range(1,10))
y=list(range(1,10))
z=list(range(1,10))
for i in np.arange(1,9,1):
r1=a[2]*y[i]-a[1]*z[i]
r2=a[0]*z[i]-a[2]*x[i]
r3=a[1]*x[i]-a[0]*y[i]
ax.plot(r1,r2,r3)
爲此,我得到的錯誤:
TypeError Traceback (most recent call
last)
<ipython-input-95-dd97076f2b6e> in <module>()
14 r2=a[0]*z[i]-a[2]*x[i]
15 r3=a[1]*x[i]-a[0]*y[i]
---> 16 ax.plot(r1,r2,r3)
1537 # Match length
1538 if not cbook.iterable(zs):
-> 1539 zs = np.ones(len(xs)) * zs
1540
1541 lines = Axes.plot(self, xs, ys, *args[argsi:],
**kwargs)
TypeError: object of type 'int' has no len()
它看上去就像是情節命令錯誤,但我無法確定它。任何幫助表示讚賞。