默认地图#
默认地图 (cedarkit.maps.map.default.DefaultMapLoader
) 使用 Cartopy 内置的 NaturalEarthFeature
绘制海岸线、陆地、河流和湖泊,使用开源项目 china-shapefiles 中国地图绘制中国边界、省界和南海九段线。
china-shapefiles 项目已内置在 cedarkit-maps 的资源目录 resources 中,无需单独安装。
准备#
导入需要的包
import numpy as np
import pandas as pd
import matplotlib.colors as mcolors
from cedarkit.maps.chart import Panel
from cedarkit.maps.domains import EastAsiaMapTemplate
from cedarkit.maps.map import set_default_map_loader_package
from cedarkit.maps.style import ContourStyle
定义绘图样式
map_colors = np.array([
(255, 255, 255),
(0, 0, 0),
(255, 255, 255),
(0, 200, 200),
(0, 210, 140),
(0, 220, 0),
(160, 230, 50),
(230, 220, 50),
(230, 175, 45),
(240, 130, 40),
(250, 60, 60),
(240, 0, 130),
(0, 0, 255),
(255, 140, 0),
(238, 18, 137)
], dtype=float) / 255
colormap = mcolors.ListedColormap(map_colors)
wind_speed_colormap = mcolors.ListedColormap(
colormap(np.array([2, 3, 4, 5, 6, 7, 8, 9, 10, 11]))
)
wind_speed_contour_lev = np.array(
[3.4, 5.5, 8, 10.8, 13.9, 17.2, 20.8, 24.5, 28.5]
)
wind_speed_style = ContourStyle(
colors=wind_speed_colormap,
levels=wind_speed_contour_lev,
fill=True,
)
绘制#
绘制地图
domain = EastAsiaMapTemplate()
panel = Panel(domain=domain)
domain.set_title(
panel=panel,
graph_name="10m Wind, 10m Wind Speed(m/s, shadow)",
system_name="CMA-MESO",
start_time=pd.to_datetime("2024-11-14 00:00"),
forecast_time=pd.to_timedelta("24h"),
)
domain.add_colorbar(panel=panel, style=wind_speed_style)
panel.show()
