我有一个描绘巡航位置的脚本。
横断面图很好但是我收到了关于绘制我的平行线的错误信息。
以下是错误消息:
Traceback (most recent call last):
File "csv_matplot.py", line 37, in <module>
map.drawparallels(np.arange(47.5, 48.5, 1), labels=[1,0,0,0])
File "...python2.7/site-packages/mpl_toolkits/basemap/__init__.py", line 2067, in drawparallels
if t is not None: linecolls[int(lat)][1].append(t)
KeyError: 47
以下是代码:
import csv
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plot
import numpy as np
#get data from csv
lat = []
lon = []
filename = raw_input("Enter file to map: ")
with open(filename, 'rU') as f:
reader = csv.DictReader(f)
for row in reader:
lat.append(row['Latitude'])
lon.append(row['Longitude'])
lats = [float(i) for i in lat]
lons = [float(i) for i in lon]
print '.....Making map of %s.....' % filename
#draw basemap
map = Basemap(projection='merc',llcrnrlat=47.5,urcrnrlat=48.5,\
llcrnrlon=-123,urcrnrlon=-122,lat_ts=10,resolution='f')
map.fillcontinents(color='green',lake_color='aqua')
map.drawmapboundary(fill_color='blue')
#insert data to basemap
x,y = map(lons, lats)
map.plot(x, y, 'r', marker = 'o', linestyle = '-', markersize=4)
map.drawparallels(np.arange(47.5, 48.5, 1), labels=[1,0,0,0])
map.drawmeridians(np.arange(-123.,-122.,.3),labels=[0,0,0,1])
plot.title(filename)
plot.show()
答案 0 :(得分:0)
好的,我认为你的matplotlib安装存在问题。
首先尝试将matplotlib更新为最新版本,如果它仍然无法正常工作试试这个:
小心并备份
在:
/usr/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.py
您必须更改以下行:
if t is not None: linecolls[int(lat)][1].append(t)
到:
if t is not None: linecolls[lat][1].append(t)