- 积分
- 192
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2018-4-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
按照站点资料画色斑图的思路,我对站点资料进行相关分析,分析后的结果画色斑图,结果色板图是下面这样。
相关分析的结果应该是没有问题,就是画图不知道怎么回事,但是我用java的MeteoInfo画出来了,不知道是不是插值算法问题,麻烦各位帮忙看看是画图哪里有问题吗?先谢谢各位了。
代码参考自
http://bbs.06climate.com/forum.php?mod=viewthread&tid=42437
以及http://bbs.06climate.com/forum.php?mod=viewthread&tid=57932&extra=page%3D1
附代码:
- import os
- import maskout2 as maskout
- import numpy as np
- import xarray as xr
- from scipy.interpolate import Rbf
- import matplotlib as mpl
- import matplotlib.pyplot as plt
- import cartopy.crs as ccrs
- import cartopy.feature as cfeature
- from cartopy.io.shapereader import Reader
- import os
- import time
- import datetime
- import pandas as pd
- last_time = time.time()
- plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文
- plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
- SHP = './shapefile/china_shp'
- root = os.path.dirname(__file__)
- SHP = os.path.join(root, SHP)
- # 数据处理
- data = pd.read_csv('corr1.csv', header=0)
- lon = data['Lon']
- lat = data['Lat']
- rain_data = data['corr']
- # 插值
- olon = np.linspace(71, 138, 88)
- olat = np.linspace(16, 56, 88)
- olon, olat = np.meshgrid(olon, olat)
- func = Rbf(lon, lat, rain_data, function='cubic')
- pre_grid = func(olon, olat)
- # 字体
- mpl.rcParams['font.sans-serif'] = ['Times New Roman']
- mpl.rc('font', size=15, weight='normal')
- font = {'family': 'SimHei', 'weight': 'normal', 'size': 15}
- # 颜色
- # 颜色
- levels = [-1.0,
- -0.872,
- -0.764,
- -0.631,
- -0.549,
- 0.0,
- 0.549,
- 0.631,
- 0.764,
- 0.872
- ]
- crgb = [
- '#200080',
- '#1000bf',
- '#0000ff',
- '#007fff',
- '#00ffff',
- '#ffff00',
- '#ff7f00',
- '#ff0000',
- '#800020',
- ]
- cmaps = mpl.colors.ListedColormap(crgb)
- norm = mpl.colors.BoundaryNorm(levels, 9)
- # 画图
- proj = ccrs.PlateCarree(central_longitude=105)
- fig = plt.figure(figsize=(16, 9), facecolor='none')
- ax = fig.add_subplot(1, 1, 1, projection=proj)
- ax.set_extent([73, 136, 15, 55], ccrs.PlateCarree())
- ax.add_geometries(Reader(os.path.join(SHP, 'cnhimap.shp')).geometries(),
- ccrs.PlateCarree(),
- facecolor='none',
- edgecolor='#737373',
- linewidth=1,
- )
- cf = ax.contourf(olon, olat, pre_grid, levels=levels, cmap=cmaps, norm=norm, zorder=0, transform=ccrs.PlateCarree())
- # 位置[左,下,右,上]
- pos_cb = []
- cb_ax = fig.add_axes()
- cbar = fig.colorbar(cf, ax=ax, orientation="vertical", aspect=25, pad=0.01, shrink=0.7)
- cbar.set_label('', fontdict=font)
- cbar.set_ticklabels(levels)
- ax.set_title('站点资料温度-降水相关分析', fontdict=font)
- # 南海
- pos1 = ax.get_position()
- # 位置[左,下,右,上]
- pos2 = [pos1.x1 - ((pos1.x1 - pos1.x0) / 7), pos1.y0, pos1.width / 7, pos1.height / 5]
- proj_n = ccrs.LambertConformal(central_latitude=90, central_longitude=115)
- ax_n = fig.add_axes(pos2, projection=proj_n)
- ax_n.set_extent([105, 125, 0, 25], ccrs.PlateCarree())
- ax_n.add_geometries(Reader(os.path.join(SHP, 'cnhimap.shp')).geometries(),
- ccrs.PlateCarree(),
- facecolor='none',
- edgecolor='k',
- linewidth=1)
- # 白化
- clip = maskout.shp2clip(cf, ax, shpfile=os.path.join(SHP, 'country1.shp'), region='China', proj=proj)
- # plt.show()
- plt.savefig('out/corr1.jpg',
- format='jpg',
- # bbox_inches='tight',
- # transparent=True,
- dpi=600) # bbox_inches='tight' 图片边界空白紧致, 背景透明
- print(f"cost: {datetime.timedelta(seconds=time.time() - last_time)} s")
复制代码
代码中使用到的相关分析结果是下面这样:
相关分析结果文件:
链接: https://pan.baidu.com/s/1GRLHfKrjuNPNzPIXJp-edA 提取码: 43ru
|
|