Han*_*gzu 5 python matplotlib grib matplotlib-basemap colormap
用于绘制某些属性的二维空间分布,contourf和pcolormesh都是可视化形式的不错选择。
由于绘图数据的实际含义,我想将零附近的值设置为白色(例如,[-0.2,0.2]);零值应该是中点
从问题 [ Defining the midpoint of a colormap in matplotlib,我尝试设置vmin和vmax调整颜色图。
import pygrib
grib='fnl_20141110_12_00.grib2';
grbs=pygrib.open(grib)
grb = grbs.select(name='Vertical velocity')[8]#Vertical velocity
data=grb.values
lat,lon = grb.latlons()
Run Code Online (Sandbox Code Playgroud)
m = Basemap(llcrnrlon=110,llcrnrlat=34,urcrnrlon=122,urcrnrlat=44,projection='mill')
fig=plt.figure(figsize=(8,4))
ax1 = plt.subplot(121)
x, y = m(lon, lat)
cs = m.contourf(x,y,data,cmap=plt.cm.RdBu)
cb = m.colorbar(cs,"bottom", size="5%", pad="8%")
ax1.set_title("Original",fontsize = 15)
ax2 = plt.subplot(122)
cs = m.contourf(x,y,data,cmap=plt.cm.RdBu,vmin = -1.8,vmax =1.8)
cb = m.colorbar(cs,"bottom", size="5%", pad="8%")
ax2.set_title("symmetrical vmin & vmax",fontsize = 15)
Run Code Online (Sandbox Code Playgroud)
m = Basemap(llcrnrlon=110,llcrnrlat=34,urcrnrlon=122,urcrnrlat=44,projection='mill')
fig=plt.figure(figsize=(8,4))
ax1 = plt.subplot(121)
cs = m.pcolormesh(x,y,data,cmap=plt.cm.RdBu)
cb = m.colorbar(cs,"bottom", size="5%", pad="8%")
ax1.set_title("Original",fontsize = 15)
ax2 = plt.subplot(122)
cs = m.pcolormesh(x,y,data,cmap=plt.cm.RdBu,vmin = -1.8,vmax =1.8)
cb = m.colorbar(cs,"bottom", size="5%", pad="8%")
ax2.set_title("symmetrical vmin & vmax",fontsize = 15)
Run Code Online (Sandbox Code Playgroud)
我将数据作为 .grib2 文件上传到此处。有兴趣的话可以下载
使用轮廓图类型,设置对称vmin并且vmax无法将零调整到颜色图的中点。这与pcolormesh不同。
相同的颜色图RdBu_r==> 和 中的结果contourf不同pcolormesh。在pcolormesh图中,颜色条的中间部分如图所示white color。但在contourf剧情中,白色似乎被忽略了。
| 归档时间: |
|
| 查看次数: |
1757 次 |
| 最近记录: |