2019-02-17 06:20:20 +00:00
|
|
|
from shapely.geometry import Point, MultiPoint
|
|
|
|
from shapely.ops import cascaded_union
|
|
|
|
import matplotlib.pyplot as plt
|
2019-02-28 10:04:47 +00:00
|
|
|
|
2019-02-17 06:20:20 +00:00
|
|
|
import pandas as pd
|
|
|
|
import cartopy.crs as ccrs
|
|
|
|
|
2019-02-28 10:04:47 +00:00
|
|
|
def draw(df, path=None):
|
2019-02-27 11:36:20 +00:00
|
|
|
biomes = {}
|
|
|
|
biome_numbers = df['biome_num'].unique()
|
|
|
|
# biome_names = df['biome_name'].unique()
|
2019-02-17 06:20:20 +00:00
|
|
|
|
2019-03-05 07:59:30 +00:00
|
|
|
for i, row in df.iterrows():
|
|
|
|
p = Point(row.longitude, row.latitude)
|
2019-02-27 11:36:20 +00:00
|
|
|
if row.biome_num in biomes:
|
|
|
|
biomes[row.biome_num].append(p)
|
|
|
|
else:
|
|
|
|
biomes[row.biome_num] = [p]
|
2019-02-17 06:20:20 +00:00
|
|
|
|
2019-02-27 11:36:20 +00:00
|
|
|
ax = plt.axes(projection=ccrs.PlateCarree())
|
|
|
|
ax.stock_img()
|
|
|
|
# ax.legend(df['biome_name'].unique())
|
2019-02-17 06:20:20 +00:00
|
|
|
|
2019-02-27 11:36:20 +00:00
|
|
|
colors={
|
|
|
|
0: '#016936',
|
|
|
|
1: '#B2D127',
|
|
|
|
2: '#77CC00',
|
|
|
|
3: '#99C500',
|
|
|
|
4: '#B6CC00',
|
|
|
|
5: '#00C5B5',
|
|
|
|
6: '#EFFF00',
|
|
|
|
7: '#FFEE00',
|
|
|
|
8: '#009BFF',
|
|
|
|
9: '#A0ADBA',
|
|
|
|
10: '#5C62FF',
|
|
|
|
11: '#00850F',
|
|
|
|
12: '#FF9E1F',
|
|
|
|
13: '#FF1F97'
|
|
|
|
}
|
2019-02-17 06:20:20 +00:00
|
|
|
|
2019-02-27 11:36:20 +00:00
|
|
|
for n in biome_numbers:
|
|
|
|
biomes[n] = MultiPoint(biomes[n]).buffer(1)
|
|
|
|
# print(biomes[n])
|
|
|
|
# legend = biome_names[n]
|
|
|
|
if not hasattr(biomes[n], '__iter__'):
|
|
|
|
biomes[n] = [biomes[n]]
|
|
|
|
ax.add_geometries(biomes[n], ccrs.PlateCarree(), facecolor=colors[n])
|
|
|
|
# artist.set_label(biome_names[n])
|
|
|
|
# print(artist.get_label())
|
2019-02-17 06:20:20 +00:00
|
|
|
|
2019-02-27 11:36:20 +00:00
|
|
|
# ax.legend(artists, biome_names)
|
2019-02-28 10:04:47 +00:00
|
|
|
if path:
|
|
|
|
plt.savefig(path)
|
|
|
|
else:
|
|
|
|
plt.show()
|
2019-02-17 06:20:20 +00:00
|
|
|
|
2019-02-27 11:36:20 +00:00
|
|
|
if __name__ == "__main__":
|
2019-03-05 07:59:30 +00:00
|
|
|
df = pd.read_pickle('data.p')
|
2019-02-27 11:36:20 +00:00
|
|
|
draw(df)
|