qq_39248684
谁抢了默默的冬瓜
2018-12-01 13:10

Python contourf函数如何只把大于某值的区域填色?

5
  • python
  • 地图

如题,如何把>0.5的区域填色,而其他区域不填色?

 names = ['num','lon','lat','XX','wind']
data = pd.read_table('D:/data/wind/out/fallingarea/2017050306.000',sep=' ',
                     skiprows=[0,1],names=names,index_col='num')
norm = Normalize()

#初始化地图
m = Basemap(projection='cyl',llcrnrlat=24.5,urcrnrlat=29.5,llcrnrlon=103,urcrnrlon=110.5)

# 将经纬度点转换为地图映射点
data['lon'], data['lat'] = m(*(data.lon.values, data.lat.values))

# 生成经纬度的栅格数据
numcols, numrows = 100, 100
xi = np.linspace(data['lon'].min(), 110, numcols)
yi = np.linspace(data['lat'].min(), 30, numcols)
xi, yi = np.meshgrid(xi, yi)

# 插值
x, y, z = data['lon'].values,data['lat'].values, data['wind'].values
#zi = gd((data[['lon','lat']]), data['wind'].values,(xi, yi),method='cubic')

func = Rbf(x,y,z,function='linear')
zi = func(xi,yi)

# 设置地图细节
m.drawcounties()
m.drawmapboundary()
m.readshapefile('D:/map/guizhoushp/Guizhou_city','states',drawbounds=True)
# 等值面图绘制
plt.scatter(x,y,z*20,marker='o',cmap='cool',alpha=0.8)
con = m.contourf(xi, yi, zi,1,alpha=0.8)
#画线的label
plt.clabel(con,inline=True,fontsize=10,colors='k')
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答