Spaces:
Sleeping
Sleeping
Update plots.py
Browse files
plots.py
CHANGED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import matplotlib.pyplot as plt
|
2 |
+
import numpy as np
|
3 |
+
import tempfile
|
4 |
+
|
5 |
+
def plot_radar_chart(config):
|
6 |
+
labels = list(config.keys())
|
7 |
+
values = list(config.values())
|
8 |
+
|
9 |
+
# Normalize boolean to int
|
10 |
+
values = [int(v) if isinstance(v, bool) else v for v in values]
|
11 |
+
|
12 |
+
angles = np.linspace(0, 2 * np.pi, len(labels), endpoint=False).tolist()
|
13 |
+
values += values[:1]
|
14 |
+
angles += angles[:1]
|
15 |
+
|
16 |
+
fig, ax = plt.subplots(figsize=(5, 5), subplot_kw=dict(polar=True))
|
17 |
+
ax.plot(angles, values, 'o-', linewidth=2)
|
18 |
+
ax.fill(angles, values, alpha=0.25)
|
19 |
+
ax.set_thetagrids(np.degrees(angles[:-1]), labels)
|
20 |
+
ax.set_title("Trait Radar", va='bottom')
|
21 |
+
ax.grid(True)
|
22 |
+
|
23 |
+
file_path = tempfile.NamedTemporaryFile(suffix=".png", delete=False).name
|
24 |
+
plt.savefig(file_path, bbox_inches="tight")
|
25 |
+
plt.close()
|
26 |
+
return file_path
|