forked from Gro/member-map
switch to matplotlib and add bundesland borders
This commit is contained in:
parent
b5883a8267
commit
6344bc1382
52
main.py
52
main.py
@ -1,11 +1,9 @@
|
||||
import argparse
|
||||
import json
|
||||
|
||||
import cartopy.crs as ccrs
|
||||
import geopandas as gpd
|
||||
import geoplot
|
||||
import geoplot.crs as gcrs
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
|
||||
def main(
|
||||
@ -29,33 +27,41 @@ def main(
|
||||
for plz_prefix in plz_prefixes:
|
||||
data.loc[data["plz"].str.startswith(plz_prefix), "highlighted"] = True
|
||||
|
||||
ax = plt.axes(projection=ccrs.TransverseMercator())
|
||||
geoplot.polyplot(
|
||||
data,
|
||||
projection=gcrs.TransverseMercator(),
|
||||
edgecolor=map_background_color,
|
||||
facecolor=map_background_color,
|
||||
linewidth=0.3,
|
||||
ax=ax,
|
||||
)
|
||||
geoplot.polyplot(
|
||||
data[data["highlighted"]],
|
||||
projection=gcrs.TransverseMercator(),
|
||||
edgecolor=map_accent_color,
|
||||
facecolor=map_accent_color,
|
||||
linewidth=0.3,
|
||||
ax=ax,
|
||||
)
|
||||
# TODO: This should instead be a proper geo spatial projection
|
||||
coordinate_transform = np.array([[1.0, 1.6]]).T
|
||||
|
||||
ax = plt.axes(aspect="equal")
|
||||
for bundesland in data["bundesland"].unique():
|
||||
bundesland_df = data[data["bundesland"] == bundesland]
|
||||
union = bundesland_df.unary_union
|
||||
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,
|
||||
)
|
||||
|
||||
if not any(bundesland_df["highlighted"]):
|
||||
continue
|
||||
|
||||
union = bundesland_df[bundesland_df["highlighted"]].unary_union
|
||||
for geom in getattr(union, "geoms", [union]):
|
||||
ax.fill(
|
||||
*(geom.exterior.xy * coordinate_transform),
|
||||
fc=map_accent_color,
|
||||
ec=None,
|
||||
)
|
||||
|
||||
ax.set_facecolor(image_background_color)
|
||||
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(
|
||||
output_file_path,
|
||||
dpi=600,
|
||||
dpi=300,
|
||||
facecolor=image_background_color,
|
||||
edgecolor="none",
|
||||
bbox_inches='tight',
|
||||
bbox_inches="tight",
|
||||
)
|
||||
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
geopandas==0.11.1
|
||||
geoplot==0.5.1
|
||||
matplotlib==3.6.2
|
Loading…
Reference in New Issue
Block a user