Overlay raster and vector using matplotlib and faceting

433
1
02-16-2022 04:50 AM
ImranJaffery
New Contributor

I'm using the function imshow from matplotlib to display several rasters using faceting. I need to overlay the vector vec.shp on each raster in each facet. I would prefere to do this with matplotlib and imshow due to the easiness of coding

import matplotlib.pyplot as plt
import gdal
import geopandas as gpd

raster1 = gdal.Open("/path/file1.tif")
raster1 = gdal.Open("/path/file2.tif")
raster1 = gdal.Open("/path/file3.tif")
# etc

vector = gpd.read_file("/path/vec.shp")

# plot 1
plt.subplot(2, 4, 1)
plt.imshow(raster1)

# plot 2 
plt.subplot(2, 4, 2)
plt.imshow(raster2)

# plot 3
plt.subplot(2, 4, 3)
plt.imshow(raster3)

# etc

I'm wondering wether is there a syntax  Like this

# plot 1
plt.subplot(2, 4, 1)
plt.imshow(raster1, vector)

 

0 Kudos
1 Reply
DanPatterson
MVP Esteemed Contributor

Can you point to an example on their examples page?

Examples — Matplotlib 3.5.1 documentation


... sort of retired...
0 Kudos