Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 62 additions & 12 deletions plots/bar-basic/implementations/plotly.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,93 @@
""" pyplots.ai
bar-basic: Basic Bar Chart
Library: plotly 6.5.0 | Python 3.13.11
Quality: 100/100 | Created: 2025-12-13
Library: plotly 6.5.2 | Python 3.14
Quality: 92/100 | Created: 2026-02-14
"""

import plotly.graph_objects as go


# Data
# Data — product sales by department, sorted descending
categories = ["Electronics", "Clothing", "Home & Garden", "Sports", "Books", "Toys", "Automotive", "Health"]
values = [45200, 38700, 31500, 27800, 24300, 21600, 18900, 15400]

# Highlight the top performer with a distinct shade
bar_colors = ["#1A4971"] + ["#306998"] * (len(categories) - 1)

# Create figure
fig = go.Figure()

fig.add_trace(
go.Bar(
x=categories,
y=values,
marker_color="#306998",
marker={"color": bar_colors, "line": {"color": "rgba(0,0,0,0.08)", "width": 1}},
text=values,
textposition="outside",
texttemplate="%{text:,.0f}",
textfont={"size": 32},
texttemplate="$%{text:,.0f}",
textfont={"size": 20, "color": "#444444"},
hovertemplate="<b>%{x}</b><br>Sales: $%{y:,.0f}<extra></extra>",
)
)

# Annotation: highlight the leading category with an insight callout
fig.add_annotation(
x="Electronics",
y=45200,
text="<b>Top seller</b><br>17% ahead of #2",
showarrow=True,
arrowhead=2,
arrowsize=1.2,
arrowwidth=2,
arrowcolor="#1A4971",
ax=100,
ay=-75,
font={"size": 18, "color": "#1A4971"},
align="left",
bordercolor="#1A4971",
borderwidth=1.5,
borderpad=6,
bgcolor="rgba(255,255,255,0.85)",
)

# Subtle average reference line
avg_value = sum(values) / len(values)
fig.add_hline(
y=avg_value,
line={"color": "rgba(0,0,0,0.25)", "width": 1.5, "dash": "dot"},
annotation={
"text": f"Avg ${avg_value:,.0f}",
"font": {"size": 16, "color": "#666666"},
"showarrow": False,
"xanchor": "left",
},
)

# Layout
fig.update_layout(
title={"text": "bar-basic · plotly · pyplots.ai", "font": {"size": 40}, "x": 0.5, "xanchor": "center"},
xaxis={"title": {"text": "Product Category", "font": {"size": 40}}, "tickfont": {"size": 32}},
title={
"text": "bar-basic · plotly · pyplots.ai",
"font": {"size": 28, "color": "#222222"},
"x": 0.5,
"xanchor": "center",
},
xaxis={
"title": {"text": "Product Category", "font": {"size": 22, "color": "#333333"}},
"tickfont": {"size": 18, "color": "#444444"},
},
yaxis={
"title": {"text": "Sales ($)", "font": {"size": 40}},
"tickfont": {"size": 32},
"gridcolor": "rgba(0,0,0,0.1)",
"title": {"text": "Sales ($)", "font": {"size": 22, "color": "#333333"}},
"tickfont": {"size": 18, "color": "#444444"},
"tickprefix": "$",
"tickformat": ",.0f",
"gridcolor": "rgba(0,0,0,0.07)",
"zeroline": False,
},
template="plotly_white",
bargap=0.3,
margin={"t": 120, "b": 80, "l": 100, "r": 50},
margin={"t": 100, "b": 80, "l": 100, "r": 120},
plot_bgcolor="white",
showlegend=False,
)

# Save
Expand Down
229 changes: 219 additions & 10 deletions plots/bar-basic/metadata/plotly.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,235 @@
library: plotly
specification_id: bar-basic
created: 2025-12-13 23:14:18+00:00
updated: 2025-12-13 23:14:18+00:00
generated_by: claude-opus-4-5-20251101
updated: '2026-02-14T14:55:26Z'
generated_by: claude-opus-4-6
workflow_run: 20199224291
issue: 612
python_version: 3.13.11
library_version: 6.5.0
python_version: '3.14'
library_version: 6.5.2
preview_url: https://storage.googleapis.com/pyplots-images/plots/bar-basic/plotly/plot.png
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/bar-basic/plotly/plot_thumb.png
preview_html: https://storage.googleapis.com/pyplots-images/plots/bar-basic/plotly/plot.html
quality_score: 100
quality_score: 92
impl_tags:
dependencies: []
techniques:
- annotations
- html-export
patterns:
- explicit-figure
patterns: []
dataprep: []
styling: []
styling:
- edge-highlighting
- grid-styling
review:
strengths: []
weaknesses: []
strengths:
- 'Excellent data storytelling with the Top seller annotation providing contextual
insight (17% ahead of #2) and the average reference line giving statistical context'
- All font sizes explicitly set and well-calibrated for 4800x2700 output — perfectly
readable
- Clean, idiomatic Plotly code with good use of library-specific features (hovertemplate,
texttemplate, add_hline with annotation)
- Thoughtful visual hierarchy with subtle darker shade for top performer and minimal
bar outlines
- Dual output (PNG + interactive HTML) leverages Plotly interactive strengths
weaknesses:
- The Top seller annotation box overlaps/crowds the $45,200 value label on the Electronics
bar, creating visual clutter at the most important data point
- The color contrast between the highlighted top bar (#1A4971) and regular bars
(#306998) is quite subtle — could be more visually distinct to reinforce the storytelling
- The average line annotation is pushed to the far right margin — could be positioned
more prominently
improvements: []
verdict: APPROVED
image_description: 'The plot displays a vertical bar chart titled "bar-basic · plotly
· pyplots.ai" centered at the top. Eight bars represent product sales by department,
sorted in descending order from left to right: Electronics ($45,200), Clothing
($38,700), Home & Garden ($31,500), Sports ($27,800), Books ($24,300), Toys ($21,600),
Automotive ($18,900), and Health ($15,400). Dollar-formatted value labels appear
above each bar. The top-performing Electronics bar is rendered in a slightly darker
navy blue (#1A4971) while the remaining bars use a medium blue (#306998). A "Top
seller / 17% ahead of #2" annotation with an arrow points to the Electronics bar.
A dotted horizontal reference line marks the average at $27,925 with a label on
the far right. The background is white with very subtle horizontal gridlines.
The x-axis is labeled "Product Category" and the y-axis "Sales ($)" with dollar-formatted
tick marks. Overall layout is clean and well-proportioned.'
criteria_checklist:
visual_quality:
score: 28
max: 30
items:
- id: VQ-01
name: Text Legibility
score: 8
max: 8
passed: true
comment: 'All font sizes explicitly set: title 28pt, axis labels 22pt, tick
labels 18pt, bar text 20pt. All perfectly readable at 4800x2700.'
- id: VQ-02
name: No Overlap
score: 4
max: 6
passed: false
comment: The Top seller annotation box and the $45,200 value label on the
Electronics bar create visual clutter; the annotation arrow and value text
compete for the same space.
- id: VQ-03
name: Element Visibility
score: 6
max: 6
passed: true
comment: Bars well-sized with appropriate bargap (0.3), all elements clearly
visible.
- id: VQ-04
name: Color Accessibility
score: 4
max: 4
passed: true
comment: Single-hue blue palette is inherently colorblind-safe. No red-green
differentiation.
- id: VQ-05
name: Layout Balance
score: 4
max: 4
passed: true
comment: Good canvas utilization with balanced margins. Plot fills appropriate
portion of canvas.
- id: VQ-06
name: Axis Labels & Title
score: 2
max: 2
passed: true
comment: Product Category and Sales ($) are descriptive with units.
design_excellence:
score: 16
max: 20
items:
- id: DE-01
name: Aesthetic Sophistication
score: 6
max: 8
passed: true
comment: Custom color palette with intentional hierarchy, subtle bar outlines,
clean plotly_white template. Clearly above defaults, strong design.
- id: DE-02
name: Visual Refinement
score: 5
max: 6
passed: true
comment: Subtle gridlines (rgba 0.07), clean template, generous whitespace,
polished margins. Average line label pushed to far right edge.
- id: DE-03
name: Data Storytelling
score: 5
max: 6
passed: true
comment: 'Top seller annotation with contextual insight (17% ahead of #2),
average reference line for context. Good narrative elements.'
spec_compliance:
score: 15
max: 15
items:
- id: SC-01
name: Plot Type
score: 5
max: 5
passed: true
comment: Correct vertical bar chart.
- id: SC-02
name: Required Features
score: 4
max: 4
passed: true
comment: Consistent bar widths, value labels above bars, single color with
highlight, adequate spacing. All spec notes addressed.
- id: SC-03
name: Data Mapping
score: 3
max: 3
passed: true
comment: Categories on x-axis, values on y-axis, correct mapping.
- id: SC-04
name: Title & Legend
score: 3
max: 3
passed: true
comment: Title format bar-basic · plotly · pyplots.ai correct. No legend needed
for single series.
data_quality:
score: 14
max: 15
items:
- id: DQ-01
name: Feature Coverage
score: 5
max: 6
passed: true
comment: 8 categories with clear variation, sorted descending. Good range
($15K-$45K). Could show more extreme variation.
- id: DQ-02
name: Realistic Context
score: 5
max: 5
passed: true
comment: Product sales by department is a real, neutral business scenario.
- id: DQ-03
name: Appropriate Scale
score: 4
max: 4
passed: true
comment: Sales figures $15K-$45K are realistic for department-level retail
sales.
code_quality:
score: 10
max: 10
items:
- id: CQ-01
name: KISS Structure
score: 3
max: 3
passed: true
comment: 'Clean flat structure: import, data, figure, annotation, layout,
save.'
- id: CQ-02
name: Reproducibility
score: 2
max: 2
passed: true
comment: Deterministic hardcoded data, no randomness needed.
- id: CQ-03
name: Clean Imports
score: 2
max: 2
passed: true
comment: Only plotly.graph_objects imported and used.
- id: CQ-04
name: Code Elegance
score: 2
max: 2
passed: true
comment: Clean, well-organized, appropriate complexity.
- id: CQ-05
name: Output & API
score: 1
max: 1
passed: true
comment: Saves as plot.png (1600x900, scale=3) and plot.html. No deprecated
APIs.
library_mastery:
score: 9
max: 10
items:
- id: LM-01
name: Idiomatic Usage
score: 5
max: 5
passed: true
comment: 'Expert use of graph_objects API: go.Bar, add_trace, update_layout,
add_annotation, add_hline with annotation dict.'
- id: LM-02
name: Distinctive Features
score: 4
max: 5
passed: true
comment: 'Uses Plotly-specific features: hovertemplate, texttemplate, add_hline
with embedded annotation, dual output (PNG + HTML).'