Skip to content

Commit 8f14eb8

Browse files
feat(seaborn): implement bar-sorted (#2560)
## Implementation: `bar-sorted` - seaborn Implements the **seaborn** version of `bar-sorted`. **File:** `plots/bar-sorted/implementations/seaborn.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20593348231)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 09be39c commit 8f14eb8

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
""" pyplots.ai
2+
bar-sorted: Sorted Bar Chart
3+
Library: seaborn 0.13.2 | Python 3.13.11
4+
Quality: 93/100 | Created: 2025-12-30
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
import numpy as np
9+
import pandas as pd
10+
import seaborn as sns
11+
12+
13+
# Data - Product sales data sorted by revenue
14+
np.random.seed(42)
15+
products = [
16+
"Electronics",
17+
"Clothing",
18+
"Home & Garden",
19+
"Sports",
20+
"Books",
21+
"Toys",
22+
"Beauty",
23+
"Automotive",
24+
"Food & Grocery",
25+
"Pet Supplies",
26+
]
27+
sales = np.array([450, 380, 320, 275, 240, 210, 185, 150, 120, 95])
28+
29+
# Create DataFrame and sort by value (descending)
30+
df = pd.DataFrame({"Product Category": products, "Sales (thousands $)": sales})
31+
df = df.sort_values("Sales (thousands $)", ascending=False)
32+
33+
# Create plot (4800x2700 px = 16x9 at 300 dpi)
34+
fig, ax = plt.subplots(figsize=(16, 9))
35+
36+
# Horizontal bar chart for better label readability
37+
sns.barplot(
38+
data=df,
39+
y="Product Category",
40+
x="Sales (thousands $)",
41+
hue="Product Category",
42+
palette=["#306998"] * len(df),
43+
legend=False,
44+
ax=ax,
45+
orient="h",
46+
)
47+
48+
# Add value labels on bars
49+
for i, value in enumerate(df["Sales (thousands $)"]):
50+
ax.text(value + 5, i, f"${value}k", va="center", fontsize=14, color="#333333")
51+
52+
# Styling
53+
ax.set_xlabel("Sales (thousands $)", fontsize=20)
54+
ax.set_ylabel("Product Category", fontsize=20)
55+
ax.set_title("bar-sorted · seaborn · pyplots.ai", fontsize=24)
56+
ax.tick_params(axis="both", labelsize=16)
57+
ax.grid(True, axis="x", alpha=0.3, linestyle="--")
58+
59+
# Extend x-axis slightly to fit labels
60+
ax.set_xlim(0, max(sales) * 1.15)
61+
62+
plt.tight_layout()
63+
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
library: seaborn
2+
specification_id: bar-sorted
3+
created: '2025-12-30T09:30:43Z'
4+
updated: '2025-12-30T09:37:18Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20593348231
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 0.13.2
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/bar-sorted/seaborn/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/bar-sorted/seaborn/plot_thumb.png
12+
preview_html: null
13+
quality_score: 93
14+
review:
15+
strengths:
16+
- Excellent horizontal layout choice for long category labels, following spec recommendation
17+
- Value labels positioned cleanly at the end of each bar with proper formatting
18+
($XXXk)
19+
- Correct use of seaborn 0.14+ API with hue parameter to avoid deprecation warnings
20+
- Clear visual hierarchy with descending sort from largest to smallest
21+
- Clean, minimal code following KISS principle
22+
- X-axis extended appropriately to prevent label clipping
23+
weaknesses:
24+
- Uses monochromatic palette instead of seaborn built-in color palettes like colorblind
25+
or Blues which could add visual interest
26+
- Grid uses dashed linestyle which is slightly more prominent than recommended

0 commit comments

Comments
 (0)