Skip to content

Commit dc87643

Browse files
feat(plotly): implement violin-box (#2677)
## Implementation: `violin-box` - plotly Implements the **plotly** version of `violin-box`. **File:** `plots/violin-box/implementations/plotly.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20595336413)* --------- 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 48fc694 commit dc87643

2 files changed

Lines changed: 113 additions & 0 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
""" pyplots.ai
2+
violin-box: Violin Plot with Embedded Box Plot
3+
Library: plotly 6.5.0 | Python 3.13.11
4+
Quality: 92/100 | Created: 2025-12-30
5+
"""
6+
7+
import numpy as np
8+
import plotly.graph_objects as go
9+
10+
11+
# Data - Test scores across different teaching methods
12+
np.random.seed(42)
13+
14+
# Generate realistic test score distributions for 4 teaching methods
15+
groups = ["Traditional", "Interactive", "Online", "Hybrid"]
16+
data = {
17+
"Traditional": np.random.normal(70, 12, 80), # Centered around 70
18+
"Interactive": np.random.normal(78, 10, 85), # Higher scores, tighter
19+
"Online": np.concatenate(
20+
[ # Bimodal distribution
21+
np.random.normal(55, 8, 40),
22+
np.random.normal(80, 7, 45),
23+
]
24+
),
25+
"Hybrid": np.random.normal(75, 15, 90), # More spread
26+
}
27+
28+
# Clip to realistic test score range (0-100)
29+
for group in groups:
30+
data[group] = np.clip(data[group], 0, 100)
31+
32+
# Colors - Python palette + accessible colors
33+
colors = ["#306998", "#FFD43B", "#4B8BBE", "#E377C2"]
34+
35+
# Create figure
36+
fig = go.Figure()
37+
38+
# Add violin with embedded box plot for each group
39+
for i, group in enumerate(groups):
40+
fig.add_trace(
41+
go.Violin(
42+
y=data[group],
43+
name=group,
44+
box_visible=True, # Show box plot inside
45+
meanline_visible=True, # Show mean line
46+
fillcolor=colors[i],
47+
opacity=0.7,
48+
line={"color": "black", "width": 1.5},
49+
points="outliers", # Show outliers
50+
pointpos=0,
51+
marker={"size": 8, "color": "black", "opacity": 0.7},
52+
box={"fillcolor": "white", "line": {"color": "black", "width": 2}, "width": 0.15},
53+
meanline={"color": "darkred", "width": 2},
54+
)
55+
)
56+
57+
# Layout for 4800x2700 px output
58+
fig.update_layout(
59+
title={
60+
"text": "violin-box · plotly · pyplots.ai",
61+
"font": {"size": 32, "color": "black"},
62+
"x": 0.5,
63+
"xanchor": "center",
64+
},
65+
xaxis={"title": {"text": "Teaching Method", "font": {"size": 24}}, "tickfont": {"size": 20}, "showgrid": False},
66+
yaxis={
67+
"title": {"text": "Test Score (points)", "font": {"size": 24}},
68+
"tickfont": {"size": 20},
69+
"gridcolor": "rgba(0,0,0,0.1)",
70+
"gridwidth": 1,
71+
"range": [0, 105],
72+
},
73+
template="plotly_white",
74+
showlegend=False,
75+
plot_bgcolor="white",
76+
paper_bgcolor="white",
77+
margin={"l": 100, "r": 50, "t": 100, "b": 100},
78+
violingap=0.3,
79+
violinmode="group",
80+
)
81+
82+
# Save as PNG (4800 x 2700 px)
83+
fig.write_image("plot.png", width=1600, height=900, scale=3)
84+
85+
# Save interactive HTML
86+
fig.write_html("plot.html", include_plotlyjs="cdn")
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
library: plotly
2+
specification_id: violin-box
3+
created: '2025-12-30T11:23:43Z'
4+
updated: '2025-12-30T11:36:23Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20595336413
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/violin-box/plotly/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/violin-box/plotly/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/violin-box/plotly/plot.html
13+
quality_score: 92
14+
review:
15+
strengths:
16+
- Excellent demonstration of bimodal distribution in Online group showcasing violin
17+
plot capability
18+
- Clean embedded box plots with visible median, quartiles, and whiskers
19+
- Mean lines (red) add extra statistical information beyond spec requirements
20+
- Realistic education scenario with plausible test score distributions
21+
- Proper output sizing (4800x2700) with readable fonts
22+
- Both PNG and interactive HTML outputs provided
23+
weaknesses:
24+
- Grid alpha at 0.1 makes gridlines very faint; could use 0.2-0.3 for better readability
25+
- Outlier markers are small (size 8); increasing to 10-12 would improve visibility
26+
- Yellow color for Interactive group may have reduced contrast for some colorblind
27+
users

0 commit comments

Comments
 (0)