fix(draw): use circle
patches instead of scatter plot
This commit is contained in:
parent
e3e3fecf4d
commit
e977239027
28
draw.py
28
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:
|
||||
|
Loading…
Reference in New Issue
Block a user