Skip to content

update(density-basic): plotly — comprehensive quality review#4382

Merged
github-actions[bot] merged 5 commits intomainfrom
implementation/density-basic/plotly
Feb 23, 2026
Merged

update(density-basic): plotly — comprehensive quality review#4382
github-actions[bot] merged 5 commits intomainfrom
implementation/density-basic/plotly

Conversation

@MarkusNeusinger
Copy link
Copy Markdown
Owner

Summary

Updated plotly implementation for density-basic.

Changes: Comprehensive quality review

Changes

  • Replaced manual KDE with scipy.stats.gaussian_kde
  • Changed data to SAT Math Scores with realistic range
  • Added units to axis labels, refined grid styling
  • Quality: 89/100 (local self-evaluation, after 2 iterations)

Test Plan

  • Preview images uploaded to GCS staging
  • Implementation file passes ruff format/check
  • Metadata YAML updated with current versions
  • Automated review triggered

Generated with Claude Code /update command

Comprehensive quality review: proper scipy KDE, SAT scores data, rug fix, refined grid.
Copilot AI review requested due to automatic review settings February 23, 2026 22:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Plotly implementation and metadata for the density-basic plot spec to improve realism and simplify KDE generation.

Changes:

  • Switched KDE computation to scipy.stats.gaussian_kde and updated the synthetic dataset to SAT Math scores.
  • Adjusted Plotly styling (fill alpha, line width, axis labeling, legend/margins) and updated metadata versions.
  • Updated metadata timestamps / generator identifier.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
plots/density-basic/metadata/plotly.yaml Updates Plotly metadata (versions, timestamps, tags, quality score).
plots/density-basic/implementations/plotly.py Updates Plotly density plot script to use SciPy KDE + SAT score data and refines presentation/export.
Comments suppressed due to low confidence (1)

plots/density-basic/metadata/plotly.yaml:28

  • The review content below still describes a manual KDE implementation and the old test-score dataset, which no longer matches the updated Plotly implementation (now uses scipy.stats.gaussian_kde and SAT scores). Please update the review.strengths/weaknesses (and image description if applicable) to reflect the current code so the metadata remains trustworthy.
  - alpha-blending
review:
  strengths:
  - Excellent manual KDE implementation using Silverman's rule of thumb for bandwidth
    selection

bandwidth = 0.9 * min(std, iqr / 1.34) * n ** (-0.2)
# KDE using scipy
kde = gaussian_kde(sat_scores)
x_grid = np.linspace(350, 800, 500)
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x_grid starts at 350, but generated SAT scores are clipped to the full 200–800 range. This means the KDE and plotted density omit the 200–350 portion of the distribution, which can hide low-score observations and contradict the “all data visible” expectation. Use a grid that spans the actual data range (e.g., from sat_scores.min()/200 to sat_scores.max()/800, with a small padding if desired).

Suggested change
x_grid = np.linspace(350, 800, 500)
x_min = max(200, sat_scores.min() - 20)
x_max = min(800, sat_scores.max() + 20)
x_grid = np.linspace(x_min, x_max, 500)

Copilot uses AI. Check for mistakes.
Comment on lines +43 to 52
# Rug plot
fig.add_trace(
go.Scatter(
x=scores,
y=[-0.001] * len(scores),
x=sat_scores,
y=np.zeros(len(sat_scores)),
mode="markers",
marker={"symbol": "line-ns", "size": 12, "color": "#306998", "line": {"width": 1.5}},
marker={"symbol": "line-ns", "size": 12, "color": "#306998", "opacity": 0.35, "line": {"width": 1.5}},
name="Observations",
hovertemplate="Score: %{x:.1f}<extra></extra>",
hovertemplate="Score: %{x:.0f}<extra></extra>",
)
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rug plot is drawn at y=0 while the density trace is filled tozeroy, so the filled area can visually obscure the rug markers at the baseline. Consider placing the rug slightly below zero (and adjusting the y-axis range accordingly) or using a secondary y-axis / different layering so the observations remain visible.

Copilot uses AI. Check for mistakes.
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/density-basic/plotly/plot_thumb.png
preview_html: https://storage.googleapis.com/pyplots-images/plots/density-basic/plotly/plot.html
quality_score: 92
quality_score: null
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quality_score is set to null, but this metadata file appears to require a numeric score (other density-basic metadata files use an integer). Please set it to the evaluated score so downstream tooling doesn’t treat the implementation as unrated.

Suggested change
quality_score: null
quality_score: 92

Copilot uses AI. Check for mistakes.
Comment on lines 14 to +24
impl_tags:
dependencies: []
techniques:
- hover-tooltips
- html-export
- hover-tooltips
- html-export
patterns:
- data-generation
- data-generation
dataprep:
- kde
- kde
styling:
- alpha-blending
- alpha-blending
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The impl_tags YAML structure is invalid: list items (- hover-tooltips, etc.) are not indented under their keys (e.g., techniques:), which will break YAML parsing (you can’t mix a mapping and sequence at the same indentation). Indent the lists under each key (or use techniques: [] style) to match the structure used in other metadata files.

Copilot uses AI. Check for mistakes.
quality_score: 92
quality_score: null
impl_tags:
dependencies: []
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The impl_tags.dependencies list is empty, but the implementation imports scipy.stats.gaussian_kde. Please add scipy as a dependency in metadata (consistent with other density-basic metadata files) so environments can install the required package.

Suggested change
dependencies: []
dependencies:
- scipy

Copilot uses AI. Check for mistakes.
Library: plotly 6.5.0 | Python 3.13.11
Quality: 92/100 | Created: 2025-12-23
Library: plotly 6.5.2 | Python 3.14
Quality: /100 | Updated: 2026-02-23
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Header docstring is missing the numeric quality score (Quality: /100). This breaks the standard 4-line header format used across plot implementations and makes it harder to track quality/regressions. Please fill in the quality score (e.g., Quality: 89/100 | Updated: 2026-02-23).

Suggested change
Quality: /100 | Updated: 2026-02-23
Quality: 92/100 | Updated: 2026-02-23

Copilot uses AI. Check for mistakes.
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Feb 23, 2026

AI Review - Attempt 1/3

Image Description

The plot displays a density curve (KDE) of SAT Math scores on a white background. The main curve is drawn in dark blue (#306998 / Python Blue) with a line width of approximately 3.5, and the area underneath is filled with a semi-transparent light blue. The curve clearly shows a bimodal distribution: a larger primary peak around 550 and a smaller secondary peak around 670-680. Along the bottom at y=0, a rug plot shows individual observations as small vertical tick marks in the same blue color with low opacity. The x-axis is labeled "SAT Math Score (points)" ranging from 350 to 800, and the y-axis is labeled "Density" ranging from 0 to ~0.0045. The title "density-basic · plotly · pyplots.ai" is centered at the top. A legend in the upper right corner shows "Density" (line) and "Observations" (tick mark) entries with a subtle white background. The y-axis has very faint horizontal grid lines; the x-axis has no grid. Overall layout is clean and professional.

Score: 87/100

Category Score Max
Visual Quality 29 30
Design Excellence 12 20
Spec Compliance 15 15
Data Quality 15 15
Code Quality 10 10
Library Mastery 6 10
Total 87 100

Visual Quality (29/30)

  • VQ-01: Text Legibility (8/8) — All font sizes explicitly set: title=36, axis labels=28, ticks=22, legend=20. All clearly readable.
  • VQ-02: No Overlap (6/6) — No overlapping text elements. Legend positioned in upper right doesn't overlap data peaks.
  • VQ-03: Element Visibility (5/6) — Density curve is clearly visible with good line width. Rug plot markers are functional but quite faint at 0.35 opacity — harder to discern at full size.
  • VQ-04: Color Accessibility (4/4) — Single-series Python Blue with good contrast against white background. No colorblind issues.
  • VQ-05: Layout & Canvas (4/4) — Plot fills canvas well with balanced margins (l=90, r=40, t=90, b=90). Nothing cut off.
  • VQ-06: Axis Labels & Title (2/2) — X-axis "SAT Math Score (points)" includes units. Y-axis "Density" is correct (unitless quantity).

Design Excellence (12/20)

  • DE-01: Aesthetic Sophistication (5/8) — Consistent Python Blue palette, plotly_white template, custom transparency on fill, clean legend styling. Above a well-configured default but not publication-showcase level.
  • DE-02: Visual Refinement (4/6) — X-axis grid removed, y-axis grid very subtle (0.15 opacity), no zeroline on either axis, legend has no border with subtle background. Clear refinement visible.
  • DE-03: Data Storytelling (3/6) — The bimodal data choice implicitly tells a story (two SAT score groups), but no visual emphasis highlights this — no annotations on peaks, no color variation, no markers. Viewer must discover the bimodality themselves.

Spec Compliance (15/15)

  • SC-01: Plot Type (5/5) — Correct: density plot using KDE smoothing.
  • SC-02: Required Features (4/4) — Smooth density curve ✓, filled area with transparency ✓, rug plot ✓, appropriate bandwidth ✓.
  • SC-03: Data Mapping (3/3) — X-axis shows continuous variable (SAT scores), Y-axis shows density. Full data range visible.
  • SC-04: Title & Legend (3/3) — Title "density-basic · plotly · pyplots.ai" matches required format. Legend labels "Density" and "Observations" are descriptive and accurate.

Data Quality (15/15)

  • DQ-01: Feature Coverage (6/6) — Bimodal distribution demonstrates modality, skewness, and shape features. Rug plot shows individual observations. Excellent coverage of density plot characteristics.
  • DQ-02: Realistic Context (5/5) — SAT Math scores: real, comprehensible, neutral educational scenario. Two groups (main performers ~540, high achievers ~680) are realistic and plausible.
  • DQ-03: Appropriate Scale (4/4) — SAT Math range 200-800 is correct. Mean values (540, 680) and standard deviations (60, 35) are realistic for SAT score distributions.

Code Quality (10/10)

  • CQ-01: KISS Structure (3/3) — Linear flow: imports → data generation → KDE → plot → save. No functions or classes.
  • CQ-02: Reproducibility (2/2) — np.random.seed(42) set.
  • CQ-03: Clean Imports (2/2) — All imports used: numpy, plotly.graph_objects, scipy.stats.gaussian_kde.
  • CQ-04: Code Elegance (2/2) — Clean, well-organized, appropriate complexity. No over-engineering.
  • CQ-05: Output & API (1/1) — Saves as plot.png via write_image() and plot.html via write_html(). Current API.

Library Mastery (6/10)

  • LM-01: Idiomatic Usage (3/5) — Uses go.Figure/go.Scatter correctly with hovertemplate for custom tooltips. However, KDE is computed entirely externally via scipy rather than exploring Plotly-native approaches (e.g., violin traces, histogram with kde overlay).
  • LM-02: Distinctive Features (3/5) — Leverages hovertemplate for formatted tooltips, write_html for interactive export, and fill="tozeroy" fill mode. These are Plotly-specific features.

Score Caps Applied

  • None — no cap conditions triggered

Strengths

  • Excellent data choice: bimodal SAT score distribution effectively showcases density plot capabilities (modality, shape, skewness)
  • Full spec compliance with all requested features (density curve, fill, rug plot)
  • All font sizes explicitly set for crisp readability at target resolution
  • Clean, well-structured code with proper reproducibility

Weaknesses

  • Rug plot markers are too faint (0.35 opacity) to be clearly visible
  • No visual emphasis on the bimodal structure — the two peaks lack annotation or highlighting
  • KDE computation done externally in scipy rather than leveraging Plotly-native approaches

Issues Found

  1. DE-03 MODERATE: Data tells an implicit story through bimodality, but no visual hierarchy guides the viewer to notice the two peaks
    • Fix: Add subtle annotations or markers on the two peaks, or use a color gradient along the curve to emphasize structure
  2. LM-01 MODERATE: KDE done entirely in scipy; Plotly used only for rendering
    • Fix: Consider using Plotly's violin trace or histogram with marginals, or enhance with Plotly-native interactive features (buttons, range sliders)
  3. VQ-03 MINOR: Rug plot at 0.35 opacity is barely visible
    • Fix: Increase rug marker opacity to 0.5-0.6 and/or increase marker size

AI Feedback for Next Attempt

To reach 90+: (1) Add visual storytelling — annotate the two peaks to highlight the bimodal structure, or use color gradients/shading to create emphasis. (2) Increase rug plot visibility (opacity to ~0.5). (3) Leverage more Plotly-native features — consider adding range slider, distribution summary stats, or interactive hover regions that showcase Plotly's interactive strengths beyond just hover tooltips.

Verdict: REJECTED

@github-actions github-actions Bot added quality:87 Quality score 87/100 ai-rejected Quality not OK, triggers update labels Feb 23, 2026
@github-actions github-actions Bot added ai-attempt-1 First repair attempt and removed ai-rejected Quality not OK, triggers update labels Feb 23, 2026
Attempt 1/3 - fixes based on AI review
Copilot AI review requested due to automatic review settings February 23, 2026 22:53
@MarkusNeusinger MarkusNeusinger review requested due to automatic review settings February 23, 2026 22:53
@github-actions
Copy link
Copy Markdown
Contributor

🔧 Repair Attempt 1/3

Applied fixes based on AI review feedback.

Status: Repair completed, re-triggering review...


🤖 impl-repair

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Feb 23, 2026

AI Review - Attempt 2/3

Image Description

The plot displays a smooth KDE density curve of SAT Math scores using Python Blue (#306998) with a semi-transparent light blue fill under the curve. The x-axis is labeled "SAT Math Score (points)" ranging from 350 to 800, and the y-axis is labeled "Density" ranging from 0 to 0.005. The title reads "density-basic · plotly · pyplots.ai" centered at the top. A bimodal distribution is clearly visible with two annotated peaks: "Primary Peak ~550 pts" pointing to the larger mode and "High Achievers ~667 pts" pointing to the secondary mode. A rug plot of individual observations appears along the x-axis as small vertical tick marks, showing data density that corresponds to the curve above. The legend in the upper-right shows "Density" (line) and "Observations" (marker). The background is white with very subtle horizontal gridlines on the y-axis only. Overall layout is clean and well-balanced.

Score: 93/100

Category Score Max
Visual Quality 30 30
Design Excellence 15 20
Spec Compliance 15 15
Data Quality 15 15
Code Quality 10 10
Library Mastery 8 10
Total 93 100

Visual Quality (30/30)

  • VQ-01: Text Legibility (8/8) — All font sizes explicitly set: title=36, axis labels=28, ticks=22, legend=20, annotations=18. All exceed minimum thresholds and are clearly readable.
  • VQ-02: No Overlap (6/6) — No overlapping text elements. Annotations are well-positioned with offset arrows. Legend sits in upper-right without obscuring data.
  • VQ-03: Element Visibility (6/6) — Density curve has 3.5px line width, clearly visible. Fill with 0.25 opacity nicely shows area. Rug plot markers (size=14, opacity=0.5) are appropriately subtle but visible.
  • VQ-04: Color Accessibility (4/4) — Single-series with Python Blue (#306998). No colorblind concerns. Good contrast against white background.
  • VQ-05: Layout & Canvas (4/4) — Plot fills ~65% of canvas. Margins (l=90, r=40, t=90, b=90) are well-balanced. Nothing cut off. Legend positioned within the plot area.
  • VQ-06: Axis Labels & Title (2/2) — X-axis: "SAT Math Score (points)" with units. Y-axis: "Density" (standard for KDE). Title in correct format.

Design Excellence (15/20)

  • DE-01: Aesthetic Sophistication (6/8) — Strong design with consistent monochromatic Python Blue scheme, semi-transparent fill, well-styled annotations with background and arrow styling. Typography is intentional with clear hierarchy (title > labels > ticks > annotations). Clearly above configured defaults.
  • DE-02: Visual Refinement (4/6) — Uses plotly_white template. X-axis grid hidden, y-axis grid at 0.15 opacity (very subtle). Zeroline removed on both axes. Legend has transparent background and no border. Spike lines configured for interactive use. Good attention to detail.
  • DE-03: Data Storytelling (5/6) — Bimodal distribution with explicitly annotated peaks ("Primary Peak" and "High Achievers") tells a clear story about two distinct populations. Rug plot reinforces the data story. Viewer immediately understands the bimodal structure. Strong focal points through annotations.

Spec Compliance (15/15)

  • SC-01: Plot Type (5/5) — Correct: density plot using Kernel Density Estimation (gaussian_kde from scipy), rendered as a smooth continuous curve.
  • SC-02: Required Features (4/4) — Smooth KDE curve ✓, fill under curve with transparency ✓, rug plot showing individual observations ✓, appropriate bandwidth (scipy default) ✓. All spec features present including optional recommendations.
  • SC-03: Data Mapping (3/3) — X-axis: continuous variable (SAT scores), Y-axis: probability density. Axes show full data range.
  • SC-04: Title & Legend (3/3) — Title: "density-basic · plotly · pyplots.ai" in correct format. Legend labels "Density" and "Observations" accurately describe the traces.

Data Quality (15/15)

  • DQ-01: Feature Coverage (6/6) — Bimodal distribution demonstrates modality identification (key density plot use case). Shows skewness, multiple peaks, and varying density. Rug plot shows individual observation distribution. Excellent showcase of what density plots reveal.
  • DQ-02: Realistic Context (5/5) — SAT Math scores: real-world, universally comprehensible, neutral educational context. Two populations (main group ~540, high achievers ~680) represent a plausible and interesting scenario.
  • DQ-03: Appropriate Scale (4/4) — SAT Math range 200-800, displayed 350-800. Means (~540, ~680) and standard deviations (60, 35) are realistic. Sample sizes (350+150=500) appropriate for KDE.

Code Quality (10/10)

  • CQ-01: KISS Structure (3/3) — Clean linear flow: imports → data generation → KDE computation → plot creation → annotations → layout → save. No functions or classes.
  • CQ-02: Reproducibility (2/2) — np.random.seed(42) set before random data generation.
  • CQ-03: Clean Imports (2/2) — Three imports (numpy, plotly.graph_objects, scipy.stats.gaussian_kde), all used. No unused imports.
  • CQ-04: Code Elegance (2/2) — Clean, readable code. Peak-finding logic is straightforward. Dict notation used consistently for Plotly parameters. No over-engineering or fake functionality.
  • CQ-05: Output & API (1/1) — Saves as plot.png via write_image(). Also generates plot.html. Uses current go.Figure/go.Scatter API.

Library Mastery (8/10)

  • LM-01: Idiomatic Usage (4/5) — Proper use of go.Figure() and go.Scatter() graph objects API. update_layout() for configuration. write_image()/write_html() for output. Hover templates for interactive tooltips. External KDE with scipy is the correct pattern since Plotly lacks a built-in KDE trace.
  • LM-02: Distinctive Features (4/5) — Leverages several Plotly-specific features: hovertemplate for custom tooltips, fill="tozeroy" for area fill, marker symbol="line-ns" for rug plot, spike lines (showspikes/spikemode/spikedash), hovermode="x", HTML export with CDN and displayModeBar config. Multiple features that don't translate to other libraries.

Score Caps Applied

  • None — no cap conditions triggered.

Strengths

  • Excellent data storytelling with annotated bimodal peaks guiding the viewer to the key insight
  • Clean, professional design with consistent Python Blue palette and subtle grid styling
  • Complete spec implementation including rug plot and filled density curve
  • Realistic SAT score data that demonstrates density plot capabilities effectively
  • Good use of Plotly-specific interactive features (hover templates, spike lines, HTML export)

Weaknesses

  • Y-axis grid could be completely removed for an even cleaner look (currently very subtle but present)
  • Monochromatic scheme limits visual excitement, though appropriate for single-series

Issues Found

None significant — implementation meets quality standards.

AI Feedback for Next Attempt

N/A — implementation approved.

Verdict: APPROVED

@github-actions github-actions Bot added quality:93 Quality score 93/100 ai-approved Quality OK, ready for merge labels Feb 23, 2026
Copilot AI review requested due to automatic review settings February 23, 2026 22:59
@MarkusNeusinger MarkusNeusinger review requested due to automatic review settings February 23, 2026 22:59
Copilot AI review requested due to automatic review settings February 23, 2026 23:00
@MarkusNeusinger MarkusNeusinger review requested due to automatic review settings February 23, 2026 23:00
@github-actions github-actions Bot merged commit 556c76e into main Feb 23, 2026
3 checks passed
@github-actions github-actions Bot deleted the implementation/density-basic/plotly branch February 23, 2026 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-approved Quality OK, ready for merge ai-attempt-1 First repair attempt quality:87 Quality score 87/100 quality:93 Quality score 93/100

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants