简体   繁体   English

在Python中使用matplotlib和带有numpy的数组绘制3D点

[英]Plot a 3D point using matplotlib and arrays with numpy in Python

I want to plot a point with an array using matplotlib, but it fails to read the array for data. 我想使用matplotlib使用数组绘制点,但是它无法读取数组中的数据。

A test case is provided here, where if I use plt.plot([1], [1], [1], 'or') it works, but if I use plt.plot(Point[0], Point[1], Point[2], 'or') it fails generating the error: 这里提供了一个测试用例,如果我使用plt.plot([1], [1], [1], 'or')它会起作用,但是如果我使用plt.plot(Point[0], Point[1], Point[2], 'or')则无法生成错误:

TypeError: object of type 'numpy.int32' has no len() TypeError:类型为“ numpy.int32”的对象没有len()

Any suggestions? 有什么建议么?

Thanks for the help! 谢谢您的帮助!

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()

as @cel told in the comments plot expects sequence of points. 正如@cel在评论图中所告诉的那样,期望点序列。 Try this for instance: 尝试例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM