Spaces:
Sleeping
Sleeping
Update plot.py
Browse files
plot.py
CHANGED
@@ -1,31 +1,28 @@
|
|
1 |
-
# plot.py
|
2 |
import matplotlib.pyplot as plt
|
3 |
import numpy as np
|
4 |
-
|
5 |
from PIL import Image
|
6 |
|
7 |
-
def plot_radar_chart(
|
8 |
-
labels = list(
|
9 |
-
values = list(
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
|
14 |
angles = np.linspace(0, 2 * np.pi, len(labels), endpoint=False).tolist()
|
15 |
-
values += values[:1]
|
16 |
angles += angles[:1]
|
17 |
|
18 |
-
fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=
|
19 |
-
ax.plot(angles, values,
|
20 |
ax.fill(angles, values, alpha=0.25)
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
ax.grid(True)
|
25 |
-
|
26 |
-
buf = BytesIO()
|
27 |
-
plt.tight_layout()
|
28 |
-
plt.savefig(buf, format="png")
|
29 |
plt.close(fig)
|
30 |
buf.seek(0)
|
31 |
return Image.open(buf)
|
|
|
|
|
1 |
import matplotlib.pyplot as plt
|
2 |
import numpy as np
|
3 |
+
import io
|
4 |
from PIL import Image
|
5 |
|
6 |
+
def plot_radar_chart(traits):
|
7 |
+
labels = list(traits.keys())
|
8 |
+
values = list(traits.values())
|
9 |
|
10 |
+
values.append(values[0]) # repeat first to close circle
|
11 |
+
labels.append(labels[0])
|
12 |
|
13 |
angles = np.linspace(0, 2 * np.pi, len(labels), endpoint=False).tolist()
|
|
|
14 |
angles += angles[:1]
|
15 |
|
16 |
+
fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(polar=True))
|
17 |
+
ax.plot(angles, values, "o-", linewidth=2)
|
18 |
ax.fill(angles, values, alpha=0.25)
|
19 |
+
ax.set_yticklabels([])
|
20 |
+
ax.set_xticks(angles[:-1])
|
21 |
+
ax.set_xticklabels(labels)
|
22 |
+
ax.set_title("Trait Radar Chart", y=1.1)
|
23 |
|
24 |
+
buf = io.BytesIO()
|
25 |
+
plt.savefig(buf, format="png", bbox_inches="tight")
|
|
|
|
|
|
|
|
|
|
|
26 |
plt.close(fig)
|
27 |
buf.seek(0)
|
28 |
return Image.open(buf)
|