switch to matplotlib and add bundesland borders

This commit is contained in:
Lukas Grossberger 2022-11-11 23:02:53 +01:00
parent b5883a8267
commit 6344bc1382
2 changed files with 30 additions and 24 deletions

48
main.py
View File

@ -1,11 +1,9 @@
import argparse import argparse
import json import json
import cartopy.crs as ccrs
import geopandas as gpd import geopandas as gpd
import geoplot
import geoplot.crs as gcrs
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np
def main( def main(
@ -29,33 +27,41 @@ def main(
for plz_prefix in plz_prefixes: for plz_prefix in plz_prefixes:
data.loc[data["plz"].str.startswith(plz_prefix), "highlighted"] = True data.loc[data["plz"].str.startswith(plz_prefix), "highlighted"] = True
ax = plt.axes(projection=ccrs.TransverseMercator()) # TODO: This should instead be a proper geo spatial projection
geoplot.polyplot( coordinate_transform = np.array([[1.0, 1.6]]).T
data,
projection=gcrs.TransverseMercator(), ax = plt.axes(aspect="equal")
edgecolor=map_background_color, for bundesland in data["bundesland"].unique():
facecolor=map_background_color, bundesland_df = data[data["bundesland"] == bundesland]
linewidth=0.3, union = bundesland_df.unary_union
ax=ax, for geom in getattr(union, "geoms", [union]):
ax.fill(
*(geom.exterior.xy * coordinate_transform),
fc=map_background_color,
ec=image_background_color,
linewidth=0.1,
) )
geoplot.polyplot(
data[data["highlighted"]], if not any(bundesland_df["highlighted"]):
projection=gcrs.TransverseMercator(), continue
edgecolor=map_accent_color,
facecolor=map_accent_color, union = bundesland_df[bundesland_df["highlighted"]].unary_union
linewidth=0.3, for geom in getattr(union, "geoms", [union]):
ax=ax, ax.fill(
*(geom.exterior.xy * coordinate_transform),
fc=map_accent_color,
ec=None,
) )
ax.set_facecolor(image_background_color) ax.set_facecolor(image_background_color)
plt.axis("off") plt.axis("off")
plt.tight_layout(pad=0.0, h_pad=None, w_pad=None) plt.tight_layout(pad=0.0, h_pad=0.0, w_pad=0.0)
plt.savefig( plt.savefig(
output_file_path, output_file_path,
dpi=600, dpi=300,
facecolor=image_background_color, facecolor=image_background_color,
edgecolor="none", edgecolor="none",
bbox_inches='tight', bbox_inches="tight",
) )

View File

@ -1,2 +1,2 @@
geopandas==0.11.1 geopandas==0.11.1
geoplot==0.5.1 matplotlib==3.6.2