首页 > 解决方案 > 如何在多个时间序列图像上绘制矢量图

问题描述

我有每月平均 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()

非常感谢任何帮助。

标签: pythonrastershapefile

解决方案


以下代码完成了这项工作:

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()

推荐阅读