python - 如何在多个时间序列图像上绘制矢量图
问题描述
我有每月平均 LMK xarray 数据集(总共 12 张图像,每个月一张图像),它是用下面的代码绘制的。我想shapefile.shp
在这些图像中的每一个上绘制和叠加。
fig, ax = plt.subplots(figsize=(5, 5))
lmk_plot = monthly_df.lmk.plot(figsize = (15, 30), col = "month", col_wrap = 3, cmap=cmap,
norm=norm, robust=True, cbar_kwargs={
"orientation": "horizontal",
"label": "custom label",
"shrink": 0.5,
"aspect": 20,
"pad": 0.03,
"label": "Mean LMK [%]",
})
lmk_plot.set_titles(size = 18)
scalebar = ScaleBar(25, location = 'lower right', length_fraction = 0.25) # 1 pixel = 0.2 meter
plt.gca().add_artist(scalebar)
plt.show()
非常感谢任何帮助。
解决方案
以下代码完成了这项工作:
import geopandas as gpd
sf_lmk = gpd.read_file('shapefile.shp')
lmk_plot = monthly_lmk.plot(figsize = (15, 30), col = "month", col_wrap = 3, cmap=cmap,
norm=norm, robust=True, cbar_kwargs={
"orientation": "horizontal",
"label": "custom label",
"shrink": 0.5,
"aspect": 20,
"pad": 0.03,
"label": "Mean LMK [%]",
})
for i, ax in enumerate(lmk_plot.axes.flat):
sf_lmk.plot(ax=ax, color=None, alpha = 1, edgecolor='black', linewidth = 2)
lmk_plot.set_titles(size = 18)
scalebar = ScaleBar(25, location = 'lower right', length_fraction = 0.25) # 1 pixel = 0.2 meter
plt.gca().add_artist(scalebar)
plt.show()
推荐阅读
- javascript - 函数内部需要模块时使用 Sinon 的函数存根
- xml - 如何区分连续/连续的“粗体”元素
- kubernetes - 我们如何使用 helm 遍历 `templates` 文件夹中的文件?
- python - 错误:无法执行“--user”安装。用户站点包在此 virtualenv 中不可见
- r - Identify origin of variable in namespace
- dart - 如何保证侦听器的调用顺序与将数据添加到 StreamController 的顺序相同
- bash - 检索包含每个文件的简短提交消息的列表
- javascript - 在对象数组上映射(错误:类型“{}”上不存在属性“映射”。TS2339)
- apache-spark - (py)SQL 语法中的 Spark getItem()
- node.js - 从 LAMBDA 触发器更新 DynanoDB