Spaces:
Sleeping
Sleeping
| # 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) | |