我正在尝试使用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()这是我得到的结果
所以我的要求是如何有一个更好的绘图,我不想把那个矩形放在中间,我希望我的结果是更多的smoothed...any想法?
发布于 2017-06-02 22:35:12
我找到了请求的答案,所以为了去掉那个矩形,我在代码中添加了以下代码:
g[g==0.0] = np.nan这意味着,密度为0的存储箱不会出现在绘图上,并且工作正常。
https://stackoverflow.com/questions/44156079
复制相似问题