Skip to content

Commit 3854b23

Browse files
feat(plotly): implement slider-control-basic (#3095)
## Implementation: `slider-control-basic` - plotly Implements the **plotly** version of `slider-control-basic`. **File:** `plots/slider-control-basic/implementations/plotly.py` **Parent Issue:** #3071 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20620342660)* --------- 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 d27f8c7 commit 3854b23

2 files changed

Lines changed: 145 additions & 0 deletions

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
""" pyplots.ai
2+
slider-control-basic: Interactive Plot with Slider Control
3+
Library: plotly 6.5.0 | Python 3.13.11
4+
Quality: 92/100 | Created: 2025-12-31
5+
"""
6+
7+
import numpy as np
8+
import plotly.graph_objects as go
9+
10+
11+
# Data - Quarterly sales data for multiple years
12+
np.random.seed(42)
13+
years = [2019, 2020, 2021, 2022, 2023, 2024]
14+
quarters = ["Q1", "Q2", "Q3", "Q4"]
15+
16+
# Generate sales data with yearly growth trend
17+
sales_data = {}
18+
base_sales = [120, 145, 160, 135] # Q1-Q4 seasonal pattern
19+
for i, year in enumerate(years):
20+
growth = 1 + i * 0.08 + np.random.uniform(-0.05, 0.05)
21+
noise = np.random.normal(0, 10, 4)
22+
sales_data[year] = np.maximum(50, np.array(base_sales) * growth + noise)
23+
24+
# Create figure with initial year (2019)
25+
fig = go.Figure()
26+
27+
# Add trace for bar chart
28+
fig.add_trace(
29+
go.Bar(
30+
x=quarters,
31+
y=sales_data[2019],
32+
marker=dict(color="#306998"),
33+
name="Quarterly Sales",
34+
text=[f"${v:.0f}K" for v in sales_data[2019]],
35+
textposition="outside",
36+
textfont=dict(size=16),
37+
)
38+
)
39+
40+
# Create slider steps
41+
steps = []
42+
for year in years:
43+
step = dict(
44+
method="update",
45+
args=[
46+
{"y": [sales_data[year]], "text": [[f"${v:.0f}K" for v in sales_data[year]]]},
47+
{
48+
"title.text": f"Quarterly Sales Performance · {year}<br><sup>slider-control-basic · plotly · pyplots.ai</sup>"
49+
},
50+
],
51+
label=str(year),
52+
)
53+
steps.append(step)
54+
55+
# Create slider
56+
sliders = [
57+
dict(
58+
active=0,
59+
currentvalue=dict(prefix="Year: ", visible=True, xanchor="center", font=dict(size=20, color="#306998")),
60+
pad=dict(t=60, b=20),
61+
len=0.7,
62+
x=0.15,
63+
xanchor="left",
64+
steps=steps,
65+
ticklen=8,
66+
tickwidth=2,
67+
font=dict(size=16),
68+
bgcolor="#E0E0E0",
69+
activebgcolor="#FFD43B",
70+
bordercolor="#306998",
71+
borderwidth=2,
72+
)
73+
]
74+
75+
# Update layout
76+
fig.update_layout(
77+
title=dict(
78+
text="Quarterly Sales Performance · 2019<br><sup>slider-control-basic · plotly · pyplots.ai</sup>",
79+
font=dict(size=28),
80+
x=0.5,
81+
xanchor="center",
82+
),
83+
xaxis=dict(title=dict(text="Quarter", font=dict(size=22)), tickfont=dict(size=18)),
84+
yaxis=dict(
85+
title=dict(text="Sales ($ Thousands)", font=dict(size=22)),
86+
tickfont=dict(size=18),
87+
range=[0, 280],
88+
gridcolor="rgba(0,0,0,0.1)",
89+
gridwidth=1,
90+
),
91+
sliders=sliders,
92+
template="plotly_white",
93+
margin=dict(t=120, b=160, l=100, r=80),
94+
showlegend=False,
95+
plot_bgcolor="white",
96+
annotations=[
97+
dict(
98+
text="Drag the slider to explore sales data by year",
99+
xref="paper",
100+
yref="paper",
101+
x=0.5,
102+
y=-0.32,
103+
showarrow=False,
104+
font=dict(size=16, color="#666666"),
105+
xanchor="center",
106+
)
107+
],
108+
)
109+
110+
# Update bar appearance
111+
fig.update_traces(marker=dict(line=dict(color="#1a3a5c", width=2)), width=0.6)
112+
113+
# Save as PNG (4800 x 2700 px)
114+
fig.write_image("plot.png", width=1600, height=900, scale=3)
115+
116+
# Save as interactive HTML
117+
fig.write_html("plot.html", include_plotlyjs=True, full_html=True)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
library: plotly
2+
specification_id: slider-control-basic
3+
created: '2025-12-31T13:53:34Z'
4+
updated: '2025-12-31T14:00:57Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20620342660
7+
issue: 3071
8+
python_version: 3.13.11
9+
library_version: 6.5.0
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/slider-control-basic/plotly/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/slider-control-basic/plotly/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/slider-control-basic/plotly/plot.html
13+
quality_score: 92
14+
review:
15+
strengths:
16+
- Excellent use of Plotly slider component with well-configured steps and currentvalue
17+
display
18+
- Clean, professional visual design with properly sized fonts and good color choice
19+
- Realistic business scenario (quarterly sales) that demonstrates the slider year-filtering
20+
capability
21+
- Dynamic title updates when slider changes year
22+
- Helpful annotation text guiding users to interact with the slider
23+
- Both PNG and HTML outputs generated for static and interactive viewing
24+
weaknesses:
25+
- Grid lines are too faint (alpha=0.1 effectively invisible) - should be more visible
26+
(alpha 0.2-0.3)
27+
- Spec mentions play/pause animation option if supported - Plotly supports this
28+
but it was not implemented

0 commit comments

Comments
 (0)