From e97723902731030429dcce104005c1694345ee44 Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Sun, 31 Mar 2019 11:59:06 +0430 Subject: [PATCH] fix(draw): use `circle` patches instead of scatter plot --- draw.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/draw.py b/draw.py index d58585b..7008d8f 100644 --- a/draw.py +++ b/draw.py @@ -1,5 +1,7 @@ import fire import matplotlib.pyplot as plt +from matplotlib.collections import PatchCollection +from matplotlib.patches import Circle, Patch from utils import logger from constants import BIOMES @@ -12,25 +14,31 @@ def draw(df, path=None): biome_numbers = df['biome_num'].unique() for i, row in df.iterrows(): + p = (row.longitude, row.latitude) if row.biome_num in biomes: - biomes[row.biome_num]['x'].append(row.longitude) - biomes[row.biome_num]['y'].append(row.latitude) + biomes[row.biome_num].append(p) else: - biomes[row.biome_num] = { 'x': [row.longitude], 'y': [row.latitude] } + biomes[row.biome_num] = [p] ax = plt.axes(projection=ccrs.PlateCarree()) ax.stock_img() - + legend_handles = [] for n in biome_numbers: - xs = biomes[n]['x'] - ys = biomes[n]['y'] - scatter = ax.scatter(xs, ys, s=4, c=BIOMES[n]['color'], transform=ccrs.PlateCarree()) - scatter.set_label(BIOMES[n]['name']) + color = BIOMES[n]['color'] - ax.legend() + patches = [Circle(p, radius=0.4) for p in biomes[n]] + collection = PatchCollection(patches, color=color) + + legend_handles.append(Patch(color=color, label=BIOMES[n]['name'])) + ax.add_collection(collection) + + ax.legend(handles=legend_handles, loc='center left', bbox_to_anchor=(1, 0.5), markerscale=4) + + ax.autoscale_view() figure = plt.gcf() - figure.set_size_inches(20, 18) + figure.set_size_inches(23.22, 13) + figure.subplots_adjust(left=0.02, right=0.79) if path: plt.savefig(path) else: