Skip to content

Commit 8b04efb

Browse files
update(candlestick-basic): altair — comprehensive quality review
Comprehensive quality review of altair implementation for candlestick-basic.
1 parent f543569 commit 8b04efb

2 files changed

Lines changed: 24 additions & 24 deletions

File tree

plots/candlestick-basic/implementations/altair.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" pyplots.ai
22
candlestick-basic: Basic Candlestick Chart
3-
Library: altair 6.0.0 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-23
3+
Library: altair 6.0.0 | Python 3.14.3
4+
Quality: /100 | Updated: 2026-02-24
55
"""
66

77
import altair as alt
@@ -12,8 +12,7 @@
1212
# Data - Simulated 30 days of stock price data
1313
np.random.seed(42)
1414
n_days = 30
15-
start_date = pd.Timestamp("2024-01-01")
16-
dates = pd.date_range(start=start_date, periods=n_days, freq="B") # Business days
15+
dates = pd.date_range(start="2024-01-01", periods=n_days, freq="B")
1716

1817
# Generate realistic OHLC data with random walk
1918
prices = [100.0]
@@ -42,22 +41,18 @@
4241
)
4342

4443
df = pd.DataFrame(data)
44+
df["direction"] = np.where(df["close"] >= df["open"], "Bullish", "Bearish")
4545

46-
# Add direction column for color encoding
47-
df["direction"] = df.apply(lambda row: "Bullish" if row["close"] >= row["open"] else "Bearish", axis=1)
48-
49-
# Color scale: green for bullish, red for bearish (most common convention)
50-
color_scale = alt.Scale(domain=["Bullish", "Bearish"], range=["#26A69A", "#EF5350"])
46+
# Colors - colorblind-safe: teal for bullish, warm orange for bearish
47+
color_scale = alt.Scale(domain=["Bullish", "Bearish"], range=["#26A69A", "#FF8F00"])
5148

5249
# Candlestick wicks (high-low lines)
5350
wicks = (
5451
alt.Chart(df)
55-
.mark_rule(strokeWidth=3)
52+
.mark_rule(strokeWidth=1.5)
5653
.encode(
57-
x=alt.X("date:T", title="Date", axis=alt.Axis(labelFontSize=18, titleFontSize=22, format="%b %d")),
58-
y=alt.Y(
59-
"low:Q", title="Price ($)", scale=alt.Scale(zero=False), axis=alt.Axis(labelFontSize=18, titleFontSize=22)
60-
),
54+
x=alt.X("date:T", title="Date", axis=alt.Axis(format="%b %d")),
55+
y=alt.Y("low:Q", title="Price ($)", scale=alt.Scale(zero=False)),
6156
y2="high:Q",
6257
color=alt.Color("direction:N", scale=color_scale, legend=None),
6358
)
@@ -66,7 +61,7 @@
6661
# Candlestick bodies (open-close bars)
6762
bodies = (
6863
alt.Chart(df)
69-
.mark_bar(size=24)
64+
.mark_bar(size=20)
7065
.encode(
7166
x="date:T",
7267
y="open:Q",
@@ -84,16 +79,21 @@
8479
)
8580
)
8681

87-
# Layer wicks and bodies
82+
# Layer wicks and bodies with interactive zoom/pan
8883
chart = (
8984
alt.layer(wicks, bodies)
85+
.resolve_scale(color="independent")
9086
.properties(
91-
width=1600, height=900, title=alt.Title("candlestick-basic · altair · pyplots.ai", fontSize=28, anchor="middle")
87+
width=1600,
88+
height=900,
89+
title=alt.Title("candlestick-basic \u00b7 altair \u00b7 pyplots.ai", fontSize=28, anchor="middle"),
9290
)
93-
.configure_axis(labelFontSize=18, titleFontSize=22, gridOpacity=0.3)
91+
.configure_axis(labelFontSize=18, titleFontSize=22, gridOpacity=0.15)
92+
.configure_legend(labelFontSize=16, titleFontSize=18)
9493
.configure_view(strokeWidth=0)
94+
.interactive()
9595
)
9696

97-
# Save as PNG and HTML
97+
# Save
9898
chart.save("plot.png", scale_factor=3.0)
9999
chart.save("plot.html")

plots/candlestick-basic/metadata/altair.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
library: altair
22
specification_id: candlestick-basic
33
created: '2025-12-23T10:01:24Z'
4-
updated: '2025-12-23T10:07:56Z'
5-
generated_by: claude-opus-4-5-20251101
4+
updated: '2026-02-24T20:50:21+00:00'
5+
generated_by: claude-opus-4-6
66
workflow_run: 20457531337
77
issue: 0
8-
python_version: 3.13.11
9-
library_version: 6.0.0
8+
python_version: "3.14.3"
9+
library_version: "6.0.0"
1010
preview_url: https://storage.googleapis.com/pyplots-images/plots/candlestick-basic/altair/plot.png
1111
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/candlestick-basic/altair/plot_thumb.png
1212
preview_html: https://storage.googleapis.com/pyplots-images/plots/candlestick-basic/altair/plot.html
13-
quality_score: 91
13+
quality_score: null
1414
impl_tags:
1515
dependencies: []
1616
techniques:

0 commit comments

Comments
 (0)