fix(draw): use circle patches instead of scatter plot

This commit is contained in:
Mahdi Dibaiee 2019-03-31 11:59:06 +04:30
parent e3e3fecf4d
commit e977239027

28
draw.py
View File

@ -1,5 +1,7 @@
import fire import fire
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from matplotlib.collections import PatchCollection
from matplotlib.patches import Circle, Patch
from utils import logger from utils import logger
from constants import BIOMES from constants import BIOMES
@ -12,25 +14,31 @@ def draw(df, path=None):
biome_numbers = df['biome_num'].unique() biome_numbers = df['biome_num'].unique()
for i, row in df.iterrows(): for i, row in df.iterrows():
p = (row.longitude, row.latitude)
if row.biome_num in biomes: if row.biome_num in biomes:
biomes[row.biome_num]['x'].append(row.longitude) biomes[row.biome_num].append(p)
biomes[row.biome_num]['y'].append(row.latitude)
else: else:
biomes[row.biome_num] = { 'x': [row.longitude], 'y': [row.latitude] } biomes[row.biome_num] = [p]
ax = plt.axes(projection=ccrs.PlateCarree()) ax = plt.axes(projection=ccrs.PlateCarree())
ax.stock_img() ax.stock_img()
legend_handles = []
for n in biome_numbers: for n in biome_numbers:
xs = biomes[n]['x'] color = BIOMES[n]['color']
ys = biomes[n]['y']
scatter = ax.scatter(xs, ys, s=4, c=BIOMES[n]['color'], transform=ccrs.PlateCarree())
scatter.set_label(BIOMES[n]['name'])
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 = 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: if path:
plt.savefig(path) plt.savefig(path)
else: else: