pip install h3pandas -i https://pypi.mirrors.ustc.edu.cn/simple/
import geopandas as gpd
shp = gpd.read_file("/home/mw/input/china1656/china_map/china_map/China_Province_2022.shp")
shp.plot()
import h3pandas
# 设置分辨率
resolution = 3
# 将地图数据重采样为六边形格子
hexagons = shp.h3.polyfill_resample(resolution)
hexagons.plot()
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.io.shapereader import BasicReader
import cartopy.feature as cfeature
provinces = BasicReader("/home/mw/input/china1656/china_map/china_map/China_Province_2022.shp")
fig = plt.figure(figsize=(15, 12),dpi=200)
ax = fig.add_subplot(111,projection=ccrs.PlateCarree())
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.COASTLINE)
ax.add_geometries(provinces.geometries(), linewidth=.5, edgecolor='black', crs=ccrs.PlateCarree(),
facecolor='none')
# 绘制六边形地图
hexagons.plot(ax=ax, color='r',alpha=0.3,edgecolor='black', linewidth=0.5) # 设置颜色和透明度
# 显示图形
plt.show()
import meteva.base as meb
filename = "/home/mw/input/meteva2260/22052019.000" # 替换为你的micaps文件路径
sta = meb.read_stadata_from_micaps3(filename)
sta.fillna(0, inplace=True)
sta.head()
level | time | dtime | id | lon | lat | data0 | |
---|---|---|---|---|---|---|---|
0 | 0 | 2022-05-20 19:00:00 | 0 | 50246 | 124.72 | 52.35 | 0.1 |
1 | 0 | 2022-05-20 19:00:00 | 0 | 50645 | 124.48 | 48.48 | 0.1 |
2 | 0 | 2022-05-20 19:00:00 | 0 | 50646 | 124.88 | 48.50 | 1.0 |
3 | 0 | 2022-05-20 19:00:00 | 0 | 50656 | 126.51 | 48.26 | 1.0 |
4 | 0 | 2022-05-20 19:00:00 | 0 | 50659 | 126.24 | 48.05 | 0.4 |
# 将站点降水数据转换为geopandas的DataFrame对象
geometry = gpd.points_from_xy(sta.lon, sta.lat)
precipitations = gpd.GeoDataFrame(sta, geometry=geometry)
# 将六边形地图表格与站点降水数据进行空间连接
merged_data = gpd.sjoin(hexagons, precipitations, op='contains')
# 计算每个六边形的平均降水量
merged_data['mean_precipitation'] = merged_data.groupby('index')['data0'].mean().reset_index()['data0']
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.io.shapereader import BasicReader
import cartopy.feature as cfeature
provinces = BasicReader("/home/mw/input/china1656/china_map/china_map/China_Province_2022.shp")
fig = plt.figure(figsize=(15, 12),dpi=200)
ax = fig.add_subplot(111,projection=ccrs.PlateCarree())
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.COASTLINE)
ax.add_geometries(provinces.geometries(), linewidth=.5, edgecolor='black', crs=ccrs.PlateCarree(),
facecolor='none')
merged_data.plot(column='mean_precipitation',ax=ax,cmap='viridis',color='r', legend=True,edgecolor='b', linewidth=0.5)
<GeoAxes: >
封面由ai绘制
prompt: color photo of a hexagonal map, with each region represented by a six-sided shape —c 10 —ar 2:3