在Matplotlib中加载文本文件时出错

时间:2015-07-24 11:58:18

标签: python unix numpy matplotlib

我试图使用matplotlib来绘制文本文件中的数据(数据格式:" lat lon value")并且我不断收到错误,我无法弄清楚如何到处走走。

数据示例:

42.88355    -76.78116   81
37.1417     -79.0164    81
36.65408    -83.21783   73
41.00928    -74.73628   69
42.29133    -73.71033   72
43.77714    -71.75598   83
44.41944    -72.01944   85
41.98525    -73.96409   82

temp.py脚本代码:

from matplotlib.mlab import load
import matplotlib.pyplot as plt
import numpy as np
data = load("/home/weather/data/.../site_data")
# need to know nlons and nlats beforehand!
nlons = 8; nlats = 25
X = data[0::nlats,0]
Y = data[0:nlats,1]
# data is in nlons,nlats order in file, need to transpose
Z = data[:,2].reshape(nlons,nlats).transpose()
X,Y = np.meshgrid(X,Y)
CS = plt.contourf(X,Y,Z,20)
plt.show()

错误:

Traceback (most recent call last):
File "temp.py", line 1, in <module>
from matplotlib.mlab import load
ImportError: cannot import name load

1 个答案:

答案 0 :(得分:1)

看起来matplotlib.mlab.load()已经deprecated。请尝试使用np.loadtxt。