如何使用matplotlib从列表中绘制多个点?

问题描述 投票:0回答:5

我已经从文本文件中读取了一个3D点列表。该列表如下所示:

content = ['2.449,14.651,-0.992,', '6.833,13.875,-1.021,', '8.133,17.431,-1.150,', '3.039,13.724,-0.999,', '16.835,9.456,-1.031,', '16.835,9.457,-1.031,', '15.388,5.893,-0.868,', '13.743,25.743,-1.394,', '14.691,24.988,-1.387,', '15.801,25.161,-1.463,', '14.668,23.056,-1.382,', '22.378,20.268,-1.457,', '21.121,17.041,-1.353,', '19.472,13.555,-1.192,', '22.498,20.115,-1.436,', '13.344,-33.672,-0.282,', '13.329,-33.835,-0.279,', '13.147,-30.690,-0.305,', '13.097,-28.407,-0.339,', '13.251,-28.643,-0.366,', '13.527,-25.067,-0.481,', '19.433,-33.137,-0.408,', '19.445,-29.501,-0.345,', '20.592,-28.004,-0.312,', '19.109,-26.512,-0.380,', '18.521,-24.155,-0.519,', '22.837,48.245,-2.201,', '23.269,50.129,-2.282,', '23.499,46.652,-2.297,', '23.814,48.646,-2.271,', '30.377,46.501,-2.214,', '29.869,44.479,-2.143,', '29.597,41.257,-2.018,', '28.134,40.291,-2.159,', '-40.932,-0.320,-1.390,', '-36.808,0.442,-1.382,', '-30.831,0.548,-1.288,', '-29.404,1.235,-1.300,', '-26.453,1.424,-1.261,', '-30.559,2.775,-1.249,', '-27.714,3.439,-1.201,']

我想绘制3D图上的所有点。到目前为止我有这个:

#!/usr/bin/env python

import numpy as np
import matplotlib.pyplot as plt

with open("measurements.txt") as f:
    content = f.read().splitlines()
#print content

for value in content:
    x, y, z = value.split(',')

#print x, y, z 
fig = plt.figure()
ax = plt.axes(projection='3d')

ax.scatter(x, y, z)

fig.savefig('scatterplot.png')

它抛出一个错误:

回溯(最近一次调用最后一次):文件“plotting.py”,第11行,x,y,z = value.split(',')ValueError:要解压的值太多

我如何绘制这些点?谢谢您的帮助。

python matplotlib
5个回答
© www.soinside.com 2019 - 2024. All rights reserved.