我有一组x y z坐标,我试图用它绘制一个三维图形。我的文本文件每行有3个值,每个值用“制表符”间距分隔。
我的代码如下:
xv = []
yv = []
zv = []
fig6 = plt.figure()
ax6 = fig6.gca(projection='3d')
with open('C:\Python27\Generate_Data\Posi_ture1803.txt') as f:
for line in f:
a, b, c = line.split('\t')
xv.append(a)
yv.append(b)
zv.append(c)
ax6.plot(xv, yv, zs=zv, label='True Position')
ax6.legend()
以下是我的错误:
Traceback (most recent call last):
File "C:\Python27\Generate_Data\gen_vehicle_location.py", line 155, in <module>
fig6.savefig('True Position.png')
File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 1363, in savefig
self.canvas.print_figure(*args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\backend_bases.py", line 2093, in print_figure
**kwargs)
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py", line 491, in print_png
FigureCanvasAgg.draw(self)
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py", line 439, in draw
self.figure.draw(self.renderer)
File "C:\Python27\lib\site-packages\matplotlib\artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 999, in draw
func(*args)
File "C:\Python27\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 214, in draw
Axes.draw(self, renderer)
File "C:\Python27\lib\site-packages\matplotlib\artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 2086, in draw
a.draw(renderer)
File "C:\Python27\lib\site-packages\mpl_toolkits\mplot3d\art3d.py", line 117, in draw
xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
File "C:\Python27\lib\site-packages\mpl_toolkits\mplot3d\proj3d.py", line 194, in proj_transform
return proj_transform_vec(vec, M)
File "C:\Python27\lib\site-packages\mpl_toolkits\mplot3d\proj3d.py", line 153, in proj_transform_vec
vecw = np.dot(M, vec)
ValueError: data type must provide an itemsize
我的值集如下:
0 0 0
4.755282581 1.545084972 1
9.510565163 3.090169944 2
14.26584774 4.635254916 3
19.02113033 6.180339887 4