2014-05-11 76 views
1

我很难过,为什么这是行不通的。我将一堆浮点数据从csv文件中拖到一个numpy数组中,我只是想根据数组中的3列创建一个3d散点图。matplotlib 3D从2d numpy阵列顶点分散错误

#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') 

标志=“0”是无效的,我的意思是打标记=“O”,一旦固定它工作得很好。

+0

你真的在这里展示完整的错误消息?坏的错误信息从来都不是好事。哪个matplotlib版本是?如果相关,请通过github将此报告给matplotlib项目。 –

回答

2

可以使用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')