summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorW. Kosior <koszko@koszko.org>2025-01-09 20:13:24 +0100
committerW. Kosior <koszko@koszko.org>2025-01-09 20:13:24 +0100
commit25a949412c58713cf8226866328d879791bdf057 (patch)
tree2d52df77d45424fce590c082d4ad21080eb4bca6
parentfa66fac68f6726d8d15b7dbd116a6b29821443e8 (diff)
downloadAGH-threat-intel-course-25a949412c58713cf8226866328d879791bdf057.tar.gz
AGH-threat-intel-course-25a949412c58713cf8226866328d879791bdf057.zip
Add legend to the map
-rwxr-xr-xcountries_motives_sectors_tables.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/countries_motives_sectors_tables.py b/countries_motives_sectors_tables.py
index f5d8e51..2ba2fc6 100755
--- a/countries_motives_sectors_tables.py
+++ b/countries_motives_sectors_tables.py
@@ -94,6 +94,7 @@ def plot_map(countries, targeting_percentages, dst_path="dst.svg"):
import geopandas as gpd
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
+ from matplotlib.patches import Patch
import pandas as pd
import math
from pathlib import Path
@@ -102,6 +103,10 @@ def plot_map(countries, targeting_percentages, dst_path="dst.svg"):
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world.plot(column='name', cmap=ListedColormap([[0.7, 0.7, 0.7]]))
+ handles = [Patch(color=color, label=origin_label)
+ for origin_label, color
+ in zip(sorted(origin_labels.values()), chart_colors)]
+ plt.legend(handles=handles, loc="lower right", fontsize="xx-small")
plt.axis("off")
plt.margins(x=0, y=0)
plt.savefig("empty_world_map.svg", bbox_inches='tight', pad_inches=0)