我正试图绘制全球气体排放图。但是,我似乎无法将我的数据(NH3idx)绘制在放大器上。我不知道是否从lat lon坐标到地图投影坐标的转换是错误的,或者我无法读取我想要绘制的数据。
import numpy as np
import pylab as plt
import math
from mpl_toolkits.basemap import Basemap
import csv
dlat = 0.1
dlon = 0.1
nlat = 1800
nlon = 3600
longrid = -180 + np.arange(nlon) * dlon
latgrid = -90 + np.arange(nlat) * dlat
NH3idx = np.zeros([nlon,nlat])
with open ('NH3_2008.txt') as csvfile:
plots = csv.reader(csvfile, delimiter=';')
for row in plots:
inlon = float(row[1])
inlat = float(row[0])
lonidx = int(abs(inlon + 180)/dlon)
latidx = int(abs(inlat +90)/dlat)
NH3idx[lonidx,latidx] = float(row[2])
plt.figure(figsize=(20,10))
m = Basemap(projection='cyl', llcrnrlat=-90,urcrnrlat=90,\
llcrnrlon=-180,urcrnrlon=180,resolution='l')
y,x = np.meshgrid(latgrid, longrid)
m.drawcoastlines()
m.drawmeridians(np.arange(-180.,180.,20.))
m.drawparallels(np.arange(-90.,90.,20.))
m.drawmapboundary(fill_color='white')
plt.contourf(x,y,NH3idx)
plt.colorbar()
plt.show()
我的数据如下:
答案 0 :(得分:0)
您需要先将坐标转换为底图坐标
X,Y = m(x,y)
然后你可能想要使用底图countour函数
m.contourf(X,Y,NH3idx)