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

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

    values.append(values[0])  # repeat first to close circle
    labels.append(labels[0])

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

    fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(polar=True))
    ax.plot(angles, values, "o-", linewidth=2)
    ax.fill(angles, values, alpha=0.25)
    ax.set_yticklabels([])
    ax.set_xticks(angles[:-1])
    ax.set_xticklabels(labels)
    ax.set_title("Trait Radar Chart", y=1.1)

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