【问题标题】:the result of density contour plot with histogram2d and matplotlibhistogram2d 和 matplotlib 的密度等高线图的结果
【发布时间】:2017-05-24 10:44:31
【问题描述】:

我正在尝试使用 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()

这是我得到的结果

所以我的要求是如何进行更好的绘图,我不想在中间有那个矩形,我希望我的结果更加平滑...有什么想法吗?

【问题讨论】:

    标签: python-2.7 matplotlib-basemap contourf


    【解决方案1】:

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

    g[g==0.0] = np.nan
    

    这意味着,密度等于 0 的 bin 不会出现在绘图上,并且工作正常。

    【讨论】:

      猜你喜欢
      • 2015-11-05
      • 2015-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-12
      • 1970-01-01
      • 2014-09-09
      • 2022-08-19
      相关资源
      最近更新 更多