用python绘制轮廓

时间:2017-05-22 14:40:04

标签: python-2.7 matplotlib-basemap contourf histogram2d

我使用包含lat / lon的csv文件绘制了histograme2d和pcolomesh的密度图。 现在我想将histogram2d输出转换为轮廓matplotlib。 我的代码如下所示:

import csv
import numpy as np
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
lats, lons = [], []
with open('fou.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=lonMin, llcrnrlat=latMin, urcrnrlon=lonMax, urcrnrlat=latMax, projection='merc', resolution='f')
m.drawcoastlines()
m.drawcountries()
m.drawstates()


db = 1 # bin padding

lon_bins = np.linspace(min(lons)-db, max(lons)+db, 100) # 10 bins
lat_bins = np.linspace(min(lats)-db, max(lats)+db, 100) # 13 bins

density, xbins, ybins =(np.histogram2d(lats, lons, [lat_bins, lon_bins]))
plt.contourf(density.transpose(),extent=[xbins[0],xbins[-1],ybins[0],ybins[-1]],levels = [1,5,10,25,50,70,80,100])
cbar = plt.colorbar(orientation='horizontal', shrink=0.625, aspect=20, fraction=0.2,pad=0.02)
cbar.set_label('the keraunic level density',size=18)
plt.gcf().set_size_inches(15,15)
plt.show()

我错过了什么?

0 个答案:

没有答案