【发布时间】:2019-12-10 05:44:44
【问题描述】:
我是python的新手。 我正在尝试绘制等高线图。 我在 data.txt 中有数据集
enter code here
#coding:utf-8
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
x = []
y = []
z = []
f = open("data1.txt")
line = f.readline()
while line:
c,d,e = line.split()
x.append(c)
y.append(d)
z.append(e)
line = f.readline()
f.close()
x = [ float ( x ) for x in x if x ]
y = [ float( y ) for y in y if y ]
z = [ float( z ) for z in z if z ]
fig=plt.figure()
ax = fig.gca(projection = '3d')
ax.plot(x,y,z)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()
然后我可以得到这样的数字 enter image description here
我希望它看起来像这样
【问题讨论】: