-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
42 lines (32 loc) · 995 Bytes
/
Copy pathsolution.py
File metadata and controls
42 lines (32 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pandas as pd
import matplotlib.pyplot as plt
import re
import json
from statsmodels.graphics.mosaicplot import mosaic
with open("data.json", "r") as text:
data = json.load(text)
for item in data:
item["Category"] = re.compile(" [\.(]").split(item["Category"])[0]
#print(data)
classes = ["Mammalia", "Aves", "Reptilia"]
statuses = ["Endangered", "Critically endangered", "Vulnerable"]
mosaic_data = []
for item in data:
if item["Animal Class"] in classes and item["Category"] in statuses:
mosaic_data.append(item)
properties = {
"Endangered": {"color": "#FACDB6"},
"Critically endangered": {"color": "#C5CADE"},
"Vulnerable": {"color": "#A8DBD2"},
}
plt.rc("font", size=8)
mosaic_dataframe = pd.DataFrame(mosaic_data)
fig = mosaic(
mosaic_dataframe,
["Category","Animal Class"],
title="Conservation Status by Animal Class",
gap=[0.02, 0.02],
axes_label=True,
properties=lambda x: properties[x[0]],
)
plt.savefig("endangered_species.png")