我正在尝试遵循https://pythonprogramming.net/3d-graphing-python-matplotlib/中的代码
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X, Y, Z = [1,2,3,4,5,6,7,8,9,10],[5,6,2,3,13,4,1,2,4,8],[2,3,3,3,5,7,9,11,9,10]
ax.plot_wireframe(X, Y, Z)
plt.show()
但是,我遇到以下错误:
AttributeError: 'list' object has no attribute 'ndim'
我尝试将列表转换为np.array
,但错误仍然存在。问题出在哪里?
答案 0 :(得分:0)
只是一些库版本兼容性问题,请尝试将d = [[1,2], [1,8], [5, 8], [3, 5]]
def t(d, r):
o = {r: []}
n = []
for e in d:
if r in e:
if e[1] == r:
e = e[::-1]
o[e[0]].append(e[1])
else:
n.append(e)
for i in o[r]:
o.update(t(n, i))
return o
print(t(d, 1))
更改为{1: [2, 8], 2: [], 8: [5], 5: [3], 3: []}
。