2015-11-13 69 views
0

我想用matplotlib绘制一个包含数组的点,但是它无法读取数据的数组。使用matplotlib和Python中的numpy绘制一个3D点

测试用例这里提供,在这里如果我使用plt.plot([1], [1], [1], 'or')它的工作原理,但如果我用plt.plot(Point[0], Point[1], Point[2], 'or')失败产生的错误:

TypeError: object of type 'numpy.int32' has no len()

有什么建议?

感谢您的帮助!

from mpl_toolkits.mplot3d import Axes3D 
import matplotlib.pyplot as plt 
from scipy.spatial import ConvexHull 
import numpy as np 

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 

ax.set_xlabel('x') 
ax.set_ylabel('y') 
ax.set_zlabel('z') 

ax.set_xlim3d(0,3) 
ax.set_ylim3d(0,3) 
ax.set_zlim3d(0,3) 

Point = np.array([1,1,1]) 
plt.plot([1], [1], [1], 'or') 
plt.plot(Point[0], Point[1], Point[2], 'or') 

plt.show() 
+1

它失败,因为'.plot()'需要一个点序列,'Point [0]'不是一个序列。 – cel

+1

请提供它引发的确切错误。 –

+0

您能否建议我使用我放入Point中的数据以使其工作?对不起,如果它可能太简单了,但我真的是新的Python –

回答

0

由于@cel在评论情节中告诉我们期望点的顺序。试试这个例如:

plt.plot([[1]], [[1]], [[1]], 'or') 
plt.plot([Point[0]], [Point[1]], [Point[2]], 'or') 
相关问题