Skip to content

Commit 724170b

Browse files
feat(seaborn): implement pie-drilldown (#3120)
## Implementation: `pie-drilldown` - seaborn Implements the **seaborn** version of `pie-drilldown`. **File:** `plots/pie-drilldown/implementations/seaborn.py` **Parent Issue:** #3072 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20620475313)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 7eb4237 commit 724170b

2 files changed

Lines changed: 170 additions & 0 deletions

File tree

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
""" pyplots.ai
2+
pie-drilldown: Drilldown Pie Chart with Click Navigation
3+
Library: seaborn 0.13.2 | Python 3.13.11
4+
Quality: 82/100 | Created: 2025-12-31
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
import seaborn as sns
10+
11+
12+
np.random.seed(42)
13+
14+
# Set seaborn style for consistent theming
15+
sns.set_theme(style="whitegrid", palette="colorblind")
16+
17+
# Data - Sales hierarchy: Region -> Category breakdown
18+
# Main level (regions)
19+
main_labels = ["North America", "Europe", "Asia Pacific", "Latin America"]
20+
main_values = [45000, 32000, 28000, 15000]
21+
main_total = sum(main_values)
22+
23+
# Drilldown data for "North America" (shown as example of drill-down view)
24+
drill_labels = ["Electronics", "Clothing", "Home & Garden", "Sports", "Books"]
25+
drill_values = [18000, 12000, 8000, 4500, 2500]
26+
drill_total = sum(drill_values)
27+
28+
# Use seaborn color palette
29+
main_colors = sns.color_palette("colorblind", n_colors=len(main_labels))
30+
drill_colors = sns.color_palette("Blues_r", n_colors=len(drill_labels))
31+
32+
# Create figure with two subplots showing drilldown concept
33+
fig, axes = plt.subplots(1, 2, figsize=(16, 9))
34+
35+
# Left chart - Main level pie chart (all regions)
36+
ax1 = axes[0]
37+
38+
# Explode the first slice to show it's selected for drilldown
39+
explode_main = [0.08, 0, 0, 0]
40+
41+
_, _, autotexts1 = ax1.pie(
42+
main_values,
43+
labels=main_labels,
44+
colors=main_colors,
45+
autopct=lambda pct: f"{pct:.1f}%\n(${int(pct * main_total / 100):,})",
46+
explode=explode_main,
47+
startangle=140,
48+
pctdistance=0.55,
49+
labeldistance=1.18,
50+
wedgeprops={"edgecolor": "white", "linewidth": 2},
51+
textprops={"fontsize": 14},
52+
)
53+
54+
# Style the percentage labels
55+
for autotext in autotexts1:
56+
autotext.set_fontsize(12)
57+
autotext.set_fontweight("bold")
58+
autotext.set_color("white")
59+
60+
# Add click indicator annotation pointing to North America
61+
ax1.annotate(
62+
"Click to\ndrill down",
63+
xy=(0.25, 0.45),
64+
xycoords="axes fraction",
65+
fontsize=12,
66+
ha="center",
67+
fontweight="bold",
68+
bbox={"boxstyle": "round,pad=0.4", "facecolor": "#FFD43B", "edgecolor": "#306998", "alpha": 0.9},
69+
arrowprops={"arrowstyle": "->", "color": "#306998", "lw": 2, "connectionstyle": "arc3,rad=0.2"},
70+
xytext=(0.05, 0.25),
71+
)
72+
73+
ax1.set_title("All Regions", fontsize=22, fontweight="bold", pad=15)
74+
75+
# Right chart - Drilldown pie chart (North America breakdown)
76+
ax2 = axes[1]
77+
78+
_, _, autotexts2 = ax2.pie(
79+
drill_values,
80+
labels=drill_labels,
81+
colors=drill_colors,
82+
autopct=lambda pct: f"{pct:.1f}%\n(${int(pct * drill_total / 100):,})",
83+
startangle=45,
84+
pctdistance=0.55,
85+
labeldistance=1.20,
86+
wedgeprops={"edgecolor": "white", "linewidth": 2},
87+
textprops={"fontsize": 14},
88+
)
89+
90+
# Style the percentage labels
91+
for autotext in autotexts2:
92+
autotext.set_fontsize(11)
93+
autotext.set_fontweight("bold")
94+
autotext.set_color("white")
95+
96+
ax2.set_title("North America Breakdown", fontsize=22, fontweight="bold", pad=15)
97+
98+
# Add breadcrumb trail above drilldown chart
99+
ax2.annotate(
100+
"All > North America",
101+
xy=(0.5, 1.08),
102+
xycoords="axes fraction",
103+
fontsize=14,
104+
ha="center",
105+
bbox={"boxstyle": "round,pad=0.4", "facecolor": "#f0f0f0", "edgecolor": "#306998", "alpha": 0.9},
106+
)
107+
108+
# Add back button indicator
109+
ax2.annotate(
110+
"← Back",
111+
xy=(0.05, 1.08),
112+
xycoords="axes fraction",
113+
fontsize=13,
114+
ha="left",
115+
color="#306998",
116+
fontweight="bold",
117+
bbox={"boxstyle": "round,pad=0.3", "facecolor": "white", "edgecolor": "#306998"},
118+
)
119+
120+
# Add arrow between charts to show drilldown flow
121+
fig.patches.extend(
122+
[plt.Arrow(0.48, 0.5, 0.04, 0, width=0.06, transform=fig.transFigure, facecolor="#306998", edgecolor="white")]
123+
)
124+
125+
# Main title
126+
fig.suptitle("pie-drilldown · seaborn · pyplots.ai", fontsize=26, fontweight="bold", y=0.98)
127+
128+
# Subtitle explaining the visualization
129+
fig.text(
130+
0.5,
131+
0.02,
132+
"Static representation of drilldown: Click any slice to explore subcategories",
133+
ha="center",
134+
fontsize=14,
135+
style="italic",
136+
color="#666666",
137+
)
138+
139+
plt.tight_layout(rect=[0, 0.05, 1, 0.93])
140+
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
library: seaborn
2+
specification_id: pie-drilldown
3+
created: '2025-12-31T14:04:27Z'
4+
updated: '2025-12-31T15:26:51Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20620475313
7+
issue: 3072
8+
python_version: 3.13.11
9+
library_version: 0.13.2
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/pie-drilldown/seaborn/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/pie-drilldown/seaborn/plot_thumb.png
12+
preview_html: null
13+
quality_score: 82
14+
review:
15+
strengths:
16+
- Effectively communicates the drilldown concept with side-by-side pie charts and
17+
connecting arrow
18+
- Excellent breadcrumb navigation and back button UI elements
19+
- Good colorblind-safe palette on main chart, appropriate sequential blues for drilldown
20+
- Clean, professional layout with clear visual hierarchy
21+
- Percentage and dollar value labels on all slices enhance readability
22+
- Click to drill down annotation clearly indicates interactivity concept
23+
weaknesses:
24+
- Seaborn is used only for theming and color palettes; core visualization uses matplotlib
25+
pie() - this is a library limitation since seaborn does not have a native pie
26+
chart function
27+
- 'Some percentage labels in smaller slices (Books: 5.6%) appear cramped within
28+
the slice'
29+
- Only demonstrates one drilldown path (North America); spec suggests showing navigation
30+
capability more fully

0 commit comments

Comments
 (0)