Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 63 additions & 37 deletions plots/radar-basic/implementations/python/seaborn.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
""" anyplot.ai
radar-basic: Basic Radar Chart
Library: seaborn 0.13.2 | Python 3.13.13
Quality: 86/100 | Updated: 2026-04-29
Library: seaborn 0.13.2 | Python 3.13.14
Quality: 90/100 | Updated: 2026-07-24
"""

import os

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns


Expand Down Expand Up @@ -37,60 +38,85 @@
},
)

# Data - Employee performance comparison across competencies
categories = ["Communication", "Technical Skills", "Teamwork", "Leadership", "Problem Solving", "Creativity"]
employee_a_values = [85, 90, 75, 70, 88, 82] # Senior Developer
employee_b_values = [78, 65, 92, 85, 72, 75] # Team Lead
# Data - product attribute comparison (0-100 scale, higher is better on every axis)
categories = ["Price", "Quality", "Durability", "Usability", "Design", "Warranty"]
budget_values = [90, 60, 65, 75, 55, 60] # Budget Model
premium_values = [45, 92, 85, 80, 90, 88] # Premium Model

n_vars = len(categories)
angles = np.linspace(0, 2 * np.pi, n_vars, endpoint=False).tolist()
angles += angles[:1] # Close the polygon

employee_a = employee_a_values + employee_a_values[:1]
employee_b = employee_b_values + employee_b_values[:1]
budget_closed = budget_values + budget_values[:1]
premium_closed = premium_values + premium_values[:1]

# Plot - square canvas for symmetric radar chart (3600x3600 at 300 dpi)
fig, ax = plt.subplots(figsize=(12, 12), subplot_kw={"projection": "polar"}, facecolor=PAGE_BG)
ax.set_facecolor(PAGE_BG)
color_budget = IMPRINT[0] # #009E73 - Budget Model (first series)
color_premium = IMPRINT[1] # #C475FD - Premium Model

color_a = IMPRINT[0] # #009E73 - Senior Developer (first series)
color_b = IMPRINT[1] # #C475FD - Team Lead
# Plot - square canvas for symmetric radar chart (2400x2400 at 400 dpi)
fig = plt.figure(figsize=(6, 6), dpi=400, facecolor=PAGE_BG)
grid = fig.add_gridspec(2, 1, height_ratios=[2.3, 1], hspace=0.4)
ax_radar = fig.add_subplot(grid[0], projection="polar")
ax_bar = fig.add_subplot(grid[1])
ax_radar.set_facecolor(PAGE_BG)
ax_bar.set_facecolor(PAGE_BG)

ax.fill(angles, employee_a, alpha=0.25, color=color_a)
ax.plot(angles, employee_a, color=color_a, linewidth=3.5, label="Senior Developer")
ax.scatter(angles[:-1], employee_a_values, color=color_a, s=150, zorder=5)
ax_radar.set_theta_offset(np.pi / 2)
ax_radar.set_theta_direction(-1)

ax.fill(angles, employee_b, alpha=0.25, color=color_b)
ax.plot(angles, employee_b, color=color_b, linewidth=3.5, label="Team Lead")
ax.scatter(angles[:-1], employee_b_values, color=color_b, s=150, zorder=5)
ax_radar.fill(angles, budget_closed, alpha=0.25, color=color_budget)
ax_radar.plot(angles, budget_closed, color=color_budget, linewidth=3, label="Budget Model")
ax_radar.scatter(angles[:-1], budget_values, color=color_budget, s=60, zorder=5)

# Style axes
ax.set_xticks(angles[:-1])
ax.set_xticklabels(categories, fontsize=20, color=INK, fontweight="medium")
ax.set_ylim(0, 100)
ax.set_yticks([20, 40, 60, 80, 100])
ax.set_yticklabels(["20", "40", "60", "80", "100"], fontsize=16, color=INK_SOFT)
ax_radar.fill(angles, premium_closed, alpha=0.25, color=color_premium)
ax_radar.plot(angles, premium_closed, color=color_premium, linewidth=3, label="Premium Model")
ax_radar.scatter(angles[:-1], premium_values, color=color_premium, s=60, zorder=5)

# Grid and spines
grid_alpha = 0.20 if THEME == "light" else 0.25
ax.grid(True, alpha=grid_alpha, linestyle="-", linewidth=1.2, color=INK_SOFT)
ax.spines["polar"].set_color(INK_SOFT)
ax.spines["polar"].set_alpha(0.4)
# Style radar axes
ax_radar.set_xticks(angles[:-1])
ax_radar.set_xticklabels(categories, fontsize=10, color=INK, fontweight="medium")
ax_radar.set_ylim(0, 100)
ax_radar.set_yticks([20, 40, 60, 80, 100])
ax_radar.set_yticklabels(["20", "40", "60", "80", "100"], fontsize=8, color=INK_SOFT)
ax_radar.set_rlabel_position(180 / n_vars) # move radial ticks into a gap between two spokes

# Title
ax.set_title("radar-basic · seaborn · anyplot.ai", fontsize=26, fontweight="medium", color=INK, pad=40)
grid_alpha = 0.20 if THEME == "light" else 0.25
ax_radar.grid(True, alpha=grid_alpha, linestyle="-", linewidth=1, color=INK_SOFT)
ax_radar.spines["polar"].set_color(INK_SOFT)
ax_radar.spines["polar"].set_alpha(0.4)

# Legend
legend = ax.legend(
legend = ax_radar.legend(
loc="upper right",
bbox_to_anchor=(1.35, 1.15),
fontsize=18,
bbox_to_anchor=(1.32, 1.15),
fontsize=8,
framealpha=0.95,
facecolor=ELEVATED_BG,
edgecolor=INK_SOFT,
)
for text in legend.get_texts():
text.set_color(INK)

# Companion score breakdown - grouped horizontal bars via seaborn's high-level API
scores = pd.DataFrame(
{
"category": categories * 2,
"value": budget_values + premium_values,
"product": ["Budget Model"] * n_vars + ["Premium Model"] * n_vars,
}
)
sns.barplot(
data=scores, x="value", y="category", hue="product", palette=[color_budget, color_premium], legend=False, ax=ax_bar
)
ax_bar.set_xlabel("Score", fontsize=10, color=INK)
ax_bar.set_ylabel("")
ax_bar.tick_params(axis="both", labelsize=8, colors=INK_SOFT)
ax_bar.set_xlim(0, 100)
ax_bar.xaxis.grid(True, alpha=0.15, linewidth=0.8, color=INK_SOFT)
ax_bar.set_axisbelow(True)
sns.despine(ax=ax_bar)

# Title
fig.suptitle("radar-basic · python · seaborn · anyplot.ai", fontsize=12, fontweight="medium", color=INK, y=0.97)

# Save
plt.savefig(f"plot-{THEME}.png", dpi=300, bbox_inches="tight", facecolor=PAGE_BG)
plt.savefig(f"plot-{THEME}.png", dpi=400, facecolor=PAGE_BG)
Loading
Loading