[英]matplotlib 3d scatter from 2d numpy array vertices error
我很困惑为什么这不起作用。 我正在从csv文件中将一堆浮点数据拖入numpy数组中,我只想根据数组中的3列创建3d散点图。
#import data from the csv file
data = np.genfromtxt('data.csv', delimiter=',', dtype=float, skiprows=1)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(data[:,1], data[:,2], data[:,7], c='r', marker='0')
plt.show()
每次我得到一个断言错误:
/usr/lib/pymodules/python2.7/matplotlib/path.pyc in __init__(self, vertices, codes, _interpolation_steps, closed)
127 codes[-1] = self.CLOSEPOLY
128
--> 129 assert vertices.ndim == 2
130 assert vertices.shape[1] == 2
131
AssertionError:
我有...只是想通了,但是我将以任何方式发布,因为那是我遇到过的最无用的错误消息。 问题出在这里:
ax.scatter(data[:,1], data[:,2], data[:,7], c='r', marker='0')
marker ='0'是无效的,我的意思是击中marker ='o',一旦修复,它就可以正常工作。
您可以使用Axes3DSubplot
对象的scatter3D()
方法:
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter3D(data[:,1], data[:,2], data[:,7], c='r', marker='0')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.