Skip to content

Commit 50b5e81

Browse files
feat(altair): implement bar-basic (#617)
## Implementation: `bar-basic` - altair Implements the **altair** version of `bar-basic`. **File:** `plots/bar-basic/implementations/altair.py` **Parent Issue:** #612 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20150015719)* --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent f4ff616 commit 50b5e81

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
bar-basic: Basic Bar Chart
3+
Library: altair
4+
"""
5+
6+
import altair as alt
7+
import pandas as pd
8+
9+
10+
# Data
11+
data = pd.DataFrame(
12+
{
13+
"category": ["Electronics", "Clothing", "Home & Garden", "Sports", "Books", "Toys", "Food"],
14+
"value": [45200, 32100, 28400, 21800, 18500, 15200, 12300],
15+
}
16+
)
17+
18+
# Chart
19+
chart = (
20+
alt.Chart(data)
21+
.mark_bar(color="#306998", cornerRadiusTopLeft=3, cornerRadiusTopRight=3)
22+
.encode(
23+
x=alt.X(
24+
"category:N",
25+
title="Product Category",
26+
sort="-y",
27+
axis=alt.Axis(labelAngle=-45, labelFontSize=16, titleFontSize=20),
28+
),
29+
y=alt.Y("value:Q", title="Sales ($)", axis=alt.Axis(labelFontSize=16, titleFontSize=20)),
30+
tooltip=[alt.Tooltip("category:N", title="Category"), alt.Tooltip("value:Q", title="Sales", format="$,.0f")],
31+
)
32+
.properties(width=1600, height=900, title=alt.Title(text="Product Sales by Category", fontSize=24))
33+
.configure_view(strokeWidth=0)
34+
.configure_axis(grid=True, gridOpacity=0.3)
35+
)
36+
37+
# Save as PNG and HTML
38+
chart.save("plot.png", scale_factor=3.0)
39+
chart.save("plot.html")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Per-library metadata for altair implementation of bar-basic
2+
# Auto-generated by impl-generate.yml
3+
4+
library: altair
5+
specification_id: bar-basic
6+
7+
preview_url: https://storage.googleapis.com/pyplots-images/plots/bar-basic/altair/plot.png
8+
preview_html: https://storage.googleapis.com/pyplots-images/plots/bar-basic/altair/plot.html
9+
10+
current:
11+
version: 0
12+
generated_at: 2025-12-11T22:54:47Z
13+
generated_by: claude-opus-4-5-20251101
14+
workflow_run: 20150015719
15+
issue: 612
16+
quality_score: 92
17+
18+
history: []

0 commit comments

Comments
 (0)