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 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(
|
||||||
geoplot.polyplot(
|
*(geom.exterior.xy * coordinate_transform),
|
||||||
data[data["highlighted"]],
|
fc=map_background_color,
|
||||||
projection=gcrs.TransverseMercator(),
|
ec=image_background_color,
|
||||||
edgecolor=map_accent_color,
|
linewidth=0.1,
|
||||||
facecolor=map_accent_color,
|
)
|
||||||
linewidth=0.3,
|
|
||||||
ax=ax,
|
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)
|
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",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
geopandas==0.11.1
|
geopandas==0.11.1
|
||||||
geoplot==0.5.1
|
matplotlib==3.6.2
|
Loading…
Reference in New Issue
Block a user