使用histogram2d和matplotlib绘制密度等值线图的结果

时间:2017-05-24 10:44:31

标签: python-2.7 matplotlib-basemap contourf

我正在尝试使用histogram2d绘制2D轮廓密度图,i2d将直方图输出转换为等高线图并用contourf绘制我的数据但是我没有意识到结果,因为它给了我一个巨大的矩形的地图中间。 这是我正在使用的代码enter image description here

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 个答案:

答案 0 :(得分:1)

我找到了我的请求的答案,所以为了摆脱那个矩形我把它添加到我的代码中:

--

这意味着,密度等于0的箱子不会出现在地块上,而且工作正常。

相关问题