Skip to content

Commit b29f40e

Browse files
feat(plotly): implement bar-error (#2387)
## Implementation: `bar-error` - plotly Implements the **plotly** version of `bar-error`. **File:** `plots/bar-error/implementations/plotly.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20543280389)* --------- 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 f032e5c commit b29f40e

2 files changed

Lines changed: 105 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
""" pyplots.ai
2+
bar-error: Bar Chart with Error Bars
3+
Library: plotly 6.5.0 | Python 3.13.11
4+
Quality: 92/100 | Created: 2025-12-27
5+
"""
6+
7+
import numpy as np
8+
import plotly.graph_objects as go
9+
10+
11+
# Data - Lab experiment comparing treatment effectiveness
12+
np.random.seed(42)
13+
categories = ["Control", "Treatment A", "Treatment B", "Treatment C", "Treatment D"]
14+
values = np.array([45.2, 62.8, 58.3, 71.5, 55.9])
15+
# Asymmetric errors to show realistic experimental variation
16+
errors_lower = np.array([4.2, 5.8, 3.9, 6.1, 4.5])
17+
errors_upper = np.array([5.1, 7.2, 4.6, 8.3, 5.8])
18+
19+
# Create figure
20+
fig = go.Figure()
21+
22+
fig.add_trace(
23+
go.Bar(
24+
x=categories,
25+
y=values,
26+
marker=dict(color="#306998", line=dict(color="#1e4d6b", width=2)),
27+
error_y=dict(
28+
type="data",
29+
symmetric=False,
30+
array=errors_upper,
31+
arrayminus=errors_lower,
32+
color="#333333",
33+
thickness=3,
34+
width=12, # Cap width
35+
),
36+
name="Measurement",
37+
)
38+
)
39+
40+
# Layout for 4800x2700 px output
41+
fig.update_layout(
42+
title=dict(
43+
text="Lab Treatment Results · bar-error · plotly · pyplots.ai",
44+
font=dict(size=32, color="#333333"),
45+
x=0.5,
46+
xanchor="center",
47+
),
48+
xaxis=dict(title=dict(text="Treatment Group", font=dict(size=24)), tickfont=dict(size=20), showgrid=False),
49+
yaxis=dict(
50+
title=dict(text="Response Value (%)", font=dict(size=24)),
51+
tickfont=dict(size=20),
52+
gridcolor="rgba(0,0,0,0.1)",
53+
gridwidth=1,
54+
range=[0, 90],
55+
),
56+
template="plotly_white",
57+
showlegend=False,
58+
margin=dict(l=100, r=80, t=120, b=100),
59+
annotations=[
60+
dict(
61+
text="Error bars: ±1 SD (asymmetric)",
62+
xref="paper",
63+
yref="paper",
64+
x=0.98,
65+
y=0.98,
66+
xanchor="right",
67+
yanchor="top",
68+
font=dict(size=18, color="#666666"),
69+
showarrow=False,
70+
)
71+
],
72+
)
73+
74+
# Save as PNG (4800x2700 px) and HTML
75+
fig.write_image("plot.png", width=1600, height=900, scale=3)
76+
fig.write_html("plot.html", include_plotlyjs="cdn")
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
library: plotly
2+
specification_id: bar-error
3+
created: '2025-12-27T19:20:48Z'
4+
updated: '2025-12-27T19:25:46Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20543280389
7+
issue: 0
8+
python_version: 3.13.11
9+
library_version: 6.5.0
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/bar-error/plotly/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/bar-error/plotly/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/bar-error/plotly/plot.html
13+
quality_score: 92
14+
review:
15+
strengths:
16+
- Excellent visual clarity with well-sized text and properly styled error bars with
17+
visible caps
18+
- Perfect spec compliance including the required annotation explaining error bar
19+
meaning
20+
- Realistic lab experiment context that demonstrates the practical use case
21+
- Clean KISS code structure following all conventions
22+
- Asymmetric error bars correctly implemented showing realistic experimental variation
23+
weaknesses:
24+
- Legend is disabled (showlegend=False) - while the annotation works, a legend entry
25+
would be more standard
26+
- Could leverage Plotly hover templates to show exact values and error ranges on
27+
interaction
28+
- Error magnitude variation across groups is relatively uniform - more dramatic
29+
differences would better showcase the feature

0 commit comments

Comments
 (0)