File size: 836 Bytes
febaebe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import matplotlib.pyplot as plt
import numpy as np
import tempfile

def plot_radar_chart(config):
    labels = list(config.keys())
    values = list(config.values())

    # Normalize boolean to int
    values = [int(v) if isinstance(v, bool) else v for v in values]

    angles = np.linspace(0, 2 * np.pi, len(labels), endpoint=False).tolist()
    values += values[:1]
    angles += angles[:1]

    fig, ax = plt.subplots(figsize=(5, 5), subplot_kw=dict(polar=True))
    ax.plot(angles, values, 'o-', linewidth=2)
    ax.fill(angles, values, alpha=0.25)
    ax.set_thetagrids(np.degrees(angles[:-1]), labels)
    ax.set_title("Trait Radar", va='bottom')
    ax.grid(True)

    file_path = tempfile.NamedTemporaryFile(suffix=".png", delete=False).name
    plt.savefig(file_path, bbox_inches="tight")
    plt.close()
    return file_path