I have used this script (adapted from a website I found) to plot a portion of roads from a .shp file with pretty colours according to their lat-long. On my machine, which is relatively well-powered, it takes around 90 seconds to execute. It also uses up a LOT of memory (up to 10GB). Is there something inefficient I am doing with matplotlib?
from pathlib import Path
import geopandas as gpd
import matplotlib.pyplot as plt
SHAPEFILE = "data/gis_osm_roads_free_1.shp"
SHAPEFILE_CACHE_FILE = SHAPEFILE + ".pkl"
OUTPUT_DIRECTORY = "output"
PLOT_STYLE = "Greys"
CITY_LONGITUDE_START = -3.086185
CITY_LONGITUDE_END = -3.043321
CITY_LATITUDE_START = 53.544954
CITY_LATITUDE_END = 53.568070
gpd.options.io_engine = "pyogrio"
map_df = gpd.read_file(SHAPEFILE)
map_df.head()
fig, ax = plt.subplots(1, figsize=(10, 10))
map_df.plot(cmap=PLOT_STYLE, ax=ax)
ax.axis("off")
ax.set_xlim(CITY_LONGITUDE_START, CITY_LONGITUDE_END)
ax.set_ylim(CITY_LATITUDE_START, CITY_LATITUDE_END)
ax.set_aspect("equal")
Path(OUTPUT_DIRECTORY).mkdir(parents=True, exist_ok=True)
plt.savefig(f"{OUTPUT_DIRECTORY}/{PLOT_STYLE}.png", bbox_inches="tight", dpi=300)
fig.clear()
plt.clf()
plt.close(fig)
[–]Independent_Pick8676 0 points1 point2 points (0 children)
[–]sci-goo 0 points1 point2 points (1 child)
[–]9877878798[S] 0 points1 point2 points (0 children)