我有一个 csv 文件,其中包含 6 年的数据(日期、经度、纬度、值)我使用 histogramm2d 和每公里轮廓线绘制了密度图,我得到了一张漂亮的地图,但我相信我绘制了每 6 年每公里的密度,所以我需要考虑知道我在文件中有多少年的标准,并绘制每年每公里而不是每 6 年的密度。所以这是我用来实现这一目标的代码:
with open('flash.csv') as f:
reader = csv.reader(f)
next(reader) # Ignore the header row.
lonMin, lonMax, dLon = -20.0, 5.0, 5
latMin, latMax, dLat = 18.0, 40.0, 5
for row in reader:
lat = float(row[2])
lon = float(row[3])
# filter lat,lons to (approximate) map view:
if lonMin <= lon <= lonMax and latMin <= lat <= latMax:
lats.append( lat )
lons.append( lon )
m = Basemap(llcrnrlon=min(lons), llcrnrlat=min(lats), urcrnrlon=max(lons), urcrnrlat=max(lats), projection='merc', resolution='f')
numcols = (max(lons)-min(lons)) * 100
numrows = (max(lats)-min(lats)) * 100
db = 1
lon_bins = np.linspace(min(lons)-db, max(lons)+db, numcols)
lat_bins = np.linspace(min(lats)-db, max(lats)+db, numrows)
h, xedges, yedges = (np.histogram2d(lats, lons,[lat_bins, lon_bins]))
xi, yi= m(*np.meshgrid(lon_bins, lat_bins))
#shape into continuous matrice
g = np.zeros(xi.shape)
g[:-1,:-1] = h
g[-1] = g[0] # copy the top row to the bottom
g[:,-1] = g[:,0] # copy the left column to the right
print g.shape,yi.shape,xi.shape
m.drawcoastlines()
m.drawstates()
g[g==0.0] = np.nan
cs = m.contourf(xi, yi, g)
cbar = plt.colorbar(cs, orientation='horizontal')
cbar.set_label('la densite des impacts foudre',size=18)
plt.gcf().set_size_inches(15,15)
plt.show()
有任何想法吗 ??