从数据csv绘制轮廓图

时间:2015-04-01 15:59:50

标签: python matplotlib

我在csv文件中有数据,其中温度,x,y和z点按列排列。 z点可以被否定,因为它通过我的数据采集保持为0。

我想简单地获得这些数据的等高线图。

我的问题与this基本相同,但它被重定向到其他线程,我仍然无法弄清楚发生了什么。

编辑:这是我未完成的代码,应该打开数据?我不知道从哪里开始。

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.mlab import griddata

import csv

data = np.genfromtxt('tempcontour0.csv', delimiter=',', dtype=[('t',float),('x',float),('y',float),('z',float)],usecols=(0,1,2))

T=data['t']
X=data['x']
Y=data['y']

z = np.zeros((len(X),2))
z[:,0] = X
z[:,1] = Y

plt.contour()
plt.show()

数据文件是这样的:

T,x,y,z
316.002,0,0,0
309.314,0.00839113,0,0
309.67,0.0172418,0,0
310.34,0.0265772,0,0
310.903,0.0364239,0,0
311.558,0.0468098,0,0
312.704,0.0577645,0,0
313.582,0.0693192,0,0
314.582,0.0815067,0,0
316.2,0.0943616,0,0
317.391,0.107921,0,0
318.93,0.122222,0,0
322.662,0.137307,0,0
325.549,0.153218,0,0
339.193,0.17,0,0
338.943,0,0.0208333,0
341.134,0.00839113,0.0208333,0
341.692,0.0172418,0.0208333,0

1 个答案:

答案 0 :(得分:-1)

首先,您必须使用以下内容读取文件:

    from numpy import genfromtxt
    import numpy as np
    import matplotlib.pyplot as plt
    data = genfromtxt('file.csv', delimiter = ',')

然后你需要绘制它,但你需要知道如何重塑数组,例如,看起来你的数据在递增y之前变为15 x值,所以:

    x = data[:, 1].reshape(15, yincrement)
    y = data[:, 2] .reshape(15,yincrement)
    z = data[:,0].reshape(15,yincrement)

    plt.contour(x,y,z)
    plt.show()