HemanM's picture
Rename plots.py to plot.py
45fdd34 verified
raw
history blame
836 Bytes
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