爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 9842|回复: 0

python

[复制链接]

新浪微博达人勋

发表于 2021-5-13 23:24:12 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
import numpy as np
import pandas as pd
import cartopy.crs as ccrs
import cartopy.feature as cfeat
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
from cartopy.io.shapereader import Reader
from scipy.interpolate import Rbf
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import sys
sys.path.append(r"C:\Users\15013\Desktop\py练习\Python完美白化_测试数据及脚本")
import maskout
plt.rcParams['font.sans-serif']=['SimHei']
extent=[90,112,24,36]
proj= ccrs.PlateCarree()
fig = plt.figure(figsize=(7, 10),dpi=500)  
ax = fig.subplots(1, 1, subplot_kw={'projection': proj})  
reader = Reader(r'C:\Users\15013\Desktop\河流\流域\流域gis\cjsy.shp')
#reader = Reader(r"C:\Users\15013\Desktop\py练习\Python完美白化_测试数据及脚本\country1.shp")
cities = cfeat.ShapelyFeature(reader.geometries(), proj, edgecolor='k', facecolor='none')
ax.add_feature(cities, linewidth=0.7)
ax.set_extent(extent, crs=proj)
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,linewidth=0.7, color='k', alpha=0.5, linestyle='--')
gl.xlabels_top = False
gl.ylabels_right = False
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
gl.xlocator = mticker.FixedLocator(np.arange(extent[0], extent[1]+3, 2))
gl.ylocator = mticker.FixedLocator(np.arange(extent[2], extent[3]+3, 2))
gl.xlabel_style={'size':10}
gl.ylabel_style={'size':10}
###########################################
filename=r'C:\Users\15013\Desktop\数据\图图\python68.xlsx'
df=pd.read_excel(filename)#读取文件
lon=df['X']#读取站点经度
lat=df['Y']#读取站点纬度
rain=df['年雨量']#读取站点累计年降水量
print(rain)
olon=np.linspace(90,112,120)#设置网格经度
olat=np.linspace(24,36,120)#设置网格纬度
olon,olat=np.meshgrid(olon,olat)#网格化
func=Rbf(lon,lat,rain,function='linear')#定义插值函数
rain_new=func(olon,olat)#获得插值后的网格累计降水量
cs= ax.contourf(olon,olat,rain_new,levels=np.arange(0,35000,4000),cmap='Blues',extend='both')#画图
##########################################################################################
position=fig.add_axes([0.25,0.3,0.5,0.02])
fig.colorbar(cs,cax=position,shrink=0.4,orientation='horizontal',label="暴雨雨量(mm)")#绘制colorbar并省称为cb
plt.show()

密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表