2017-05-24 91 views
1

我想繪製一個2D輪廓密度圖,使用histogram2d,i2d將直方圖輸出轉化爲等值線圖,並用contourf繪製我的數據,但我沒有讚賞結果,因爲它給了我一張中間有一個巨大矩形的地圖。 這裏是我使用enter image description here密度等高線繪製與histogram2d和matplotlib的結果

db = 1 
lon_bins = np.linspace(min(lons)-db, max(lons)+db, (max(lons)-min(lons))*100) 
lat_bins = np.linspace(min(lats)-db, max(lats)+db, (max(lats)-min(lats))*100) 

h, xedges, yedges = (np.histogram2d(lats, lons,[lat_bins, lon_bins]) 
yi, xi = m(*np.meshgrid(lon_bins, lat_bins)) 
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 

cs = m.contourf(yi, xi, g, cmap='Dark2') 
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() 

代碼而這裏的結果我得到

所以我的要求是如何有一個更好的繪圖,我不希望有一個長方形的中間,我希望我的結果更加平滑......任何想法?

回答

1

我發現我的請求的答覆,所以爲了擺脫矩形i將此添加到我的代碼:

g[g==0.0] = np.nan 

這意味着,具有密度等於0的垃圾箱將不會出現在情節上,它的工作正常。