Skip to content

Commit 527fef1

Browse files
feat(plotly): implement parallel-categories-basic (#2528)
## Implementation: `parallel-categories-basic` - plotly Implements the **plotly** version of `parallel-categories-basic`. **File:** `plots/parallel-categories-basic/implementations/plotly.py` --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20585400189)* --------- 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 8af66ef commit 527fef1

2 files changed

Lines changed: 120 additions & 0 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
""" pyplots.ai
2+
parallel-categories-basic: Basic Parallel Categories Plot
3+
Library: plotly 6.5.0 | Python 3.13.11
4+
Quality: 92/100 | Created: 2025-12-30
5+
"""
6+
7+
import plotly.graph_objects as go
8+
import seaborn as sns
9+
10+
11+
# Data - Titanic survival data with multiple categorical dimensions
12+
df = sns.load_dataset("titanic")
13+
14+
# Prepare data: select key categorical variables
15+
df = df[["class", "sex", "embarked", "survived"]].dropna()
16+
17+
# Map survived to readable labels
18+
df["outcome"] = df["survived"].map({0: "Did Not Survive", 1: "Survived"})
19+
20+
# Create dimension specifications for parallel categories
21+
dimensions = [
22+
{
23+
"label": "Passenger Class",
24+
"values": df["class"].astype(str),
25+
"categoryorder": "array",
26+
"categoryarray": ["First", "Second", "Third"],
27+
},
28+
{
29+
"label": "Sex",
30+
"values": df["sex"].str.capitalize(),
31+
"categoryorder": "array",
32+
"categoryarray": ["Female", "Male"],
33+
},
34+
{
35+
"label": "Embarked",
36+
"values": df["embarked"].map({"C": "Cherbourg", "Q": "Queenstown", "S": "Southampton"}),
37+
"categoryorder": "array",
38+
"categoryarray": ["Cherbourg", "Queenstown", "Southampton"],
39+
},
40+
{
41+
"label": "Outcome",
42+
"values": df["outcome"],
43+
"categoryorder": "array",
44+
"categoryarray": ["Survived", "Did Not Survive"],
45+
},
46+
]
47+
48+
# Create color scale based on survival outcome (last dimension)
49+
color_values = df["survived"].values
50+
51+
# Create parallel categories plot
52+
fig = go.Figure(
53+
go.Parcats(
54+
dimensions=dimensions,
55+
line={
56+
"color": color_values,
57+
"colorscale": [[0, "#306998"], [1, "#FFD43B"]], # Python Blue for not survived, Yellow for survived
58+
"shape": "hspline",
59+
},
60+
hoveron="color",
61+
hoverinfo="count+probability",
62+
arrangement="freeform",
63+
)
64+
)
65+
66+
# Update layout for 4800x2700 canvas
67+
fig.update_layout(
68+
title={
69+
"text": "Titanic Passengers · parallel-categories-basic · plotly · pyplots.ai",
70+
"font": {"size": 32, "color": "#333333"},
71+
"x": 0.5,
72+
"xanchor": "center",
73+
},
74+
font={"size": 20},
75+
paper_bgcolor="white",
76+
plot_bgcolor="white",
77+
margin={"l": 80, "r": 80, "t": 120, "b": 80},
78+
annotations=[
79+
{
80+
"text": "Color: Yellow = Survived, Blue = Did Not Survive",
81+
"x": 0.5,
82+
"y": -0.08,
83+
"xref": "paper",
84+
"yref": "paper",
85+
"showarrow": False,
86+
"font": {"size": 18, "color": "#666666"},
87+
"xanchor": "center",
88+
}
89+
],
90+
)
91+
92+
# Save as PNG (4800 x 2700 px)
93+
fig.write_image("plot.png", width=1600, height=900, scale=3)
94+
95+
# Save interactive HTML
96+
fig.write_html("plot.html", include_plotlyjs=True, full_html=True)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
library: plotly
2+
specification_id: parallel-categories-basic
3+
created: '2025-12-30T00:05:08Z'
4+
updated: '2025-12-30T00:13:23Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20585400189
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/parallel-categories-basic/plotly/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/parallel-categories-basic/plotly/plot_thumb.png
12+
preview_html: https://storage.googleapis.com/pyplots-images/plots/parallel-categories-basic/plotly/plot.html
13+
quality_score: 92
14+
review:
15+
strengths:
16+
- Excellent use of Titanic dataset providing realistic, well-known categorical data
17+
with meaningful dimensions
18+
- Clear color scheme with blue/yellow contrast that is colorblind-friendly
19+
- Good use of Plotly Parcats with smooth hspline ribbons and interactive hover features
20+
- Title follows correct format with spec-id, library, and pyplots.ai branding
21+
- Helpful annotation explaining color meaning at the bottom of the plot
22+
weaknesses:
23+
- The Did Not Survive label on the right side is slightly cut off - consider adjusting
24+
margins or abbreviating

0 commit comments

Comments
 (0)