File size: 879 Bytes
848a355
febaebe
 
b0fd119
848a355
febaebe
 
b0fd119
 
 
 
 
 
 
febaebe
 
 
b0fd119
 
febaebe
 
b0fd119
 
 
 
 
 
848a355
b0fd119
848a355
b0fd119
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
# plot.py
import matplotlib.pyplot as plt
import numpy as np
from io import BytesIO
from PIL import Image

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

    # Convert boolean to numeric for plotting
    values = [1 if v is True else 0 if v is False 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=(6, 6), subplot_kw={'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 Chart", fontsize=14)
    ax.grid(True)

    buf = BytesIO()
    plt.tight_layout()
    plt.savefig(buf, format="png")
    plt.close(fig)
    buf.seek(0)
    return Image.open(buf)