Skip to content

Commit b24bacd

Browse files
update(arc-basic): plotnine — comprehensive quality review
Comprehensive review and update of plotnine implementation for arc-basic.
1 parent b1e8c8c commit b24bacd

2 files changed

Lines changed: 41 additions & 58 deletions

File tree

Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
""" pyplots.ai
1+
"""pyplots.ai
22
arc-basic: Basic Arc Diagram
3-
Library: plotnine 0.15.2 | Python 3.13.11
4-
Quality: 91/100 | Created: 2025-12-23
3+
Library: plotnine 0.15.3 | Python 3.14.3
4+
Quality: /100 | Updated: 2026-02-23
55
"""
66

77
import sys
@@ -13,27 +13,28 @@
1313
import pandas as pd # noqa: E402
1414
from plotnine import ( # noqa: E402
1515
aes,
16+
coord_cartesian,
1617
element_blank,
18+
element_rect,
1719
element_text,
1820
geom_path,
1921
geom_point,
2022
geom_text,
2123
ggplot,
2224
labs,
25+
scale_alpha_identity,
2326
scale_size_identity,
2427
theme,
2528
)
2629

2730

2831
# Data: Character interactions in a story chapter
29-
np.random.seed(42)
30-
3132
nodes = ["Alice", "Bob", "Carol", "David", "Eve", "Frank", "Grace", "Henry", "Iris", "Jack"]
3233
n_nodes = len(nodes)
3334

34-
# Edges: pairs of connected nodes with weights (source, target, weight)
35+
# Edges: (source_idx, target_idx, weight)
3536
edges = [
36-
(0, 1, 3), # Alice-Bob (strong connection)
37+
(0, 1, 3), # Alice-Bob (strong)
3738
(0, 3, 2), # Alice-David
3839
(1, 2, 2), # Bob-Carol
3940
(2, 4, 1), # Carol-Eve
@@ -52,74 +53,56 @@
5253

5354
# Node positions along x-axis
5455
x_positions = np.linspace(0, 1, n_nodes)
55-
y_baseline = 0.1
56-
57-
# Create arc paths dataframe
58-
arc_data = []
59-
arc_id = 0
56+
y_baseline = 0.0
6057

61-
for start, end, weight in edges:
62-
x_start = x_positions[start]
63-
x_end = x_positions[end]
58+
# Build arc paths using vectorized construction
59+
n_points = 50
60+
theta = np.linspace(0, np.pi, n_points)
61+
arc_rows = []
6462

65-
# Arc center and radius
63+
for arc_id, (start, end, weight) in enumerate(edges):
64+
x_start, x_end = x_positions[start], x_positions[end]
6665
x_center = (x_start + x_end) / 2
6766
arc_radius = abs(x_end - x_start) / 2
67+
height = 0.08 * abs(end - start)
6868

69-
# Arc height proportional to distance between nodes
70-
distance = abs(end - start)
71-
height = 0.08 * distance
72-
73-
# Generate arc points (semi-circle above baseline)
74-
n_points = 50
75-
theta = np.linspace(0, np.pi, n_points)
7669
x_arc = x_center - arc_radius * np.cos(theta)
7770
y_arc = y_baseline + height * np.sin(theta)
7871

79-
# Add points to dataframe with arc identifier
80-
for i in range(n_points):
81-
arc_data.append(
82-
{
83-
"x": x_arc[i],
84-
"y": y_arc[i],
85-
"arc_id": arc_id,
86-
"weight": weight,
87-
"size": 1.0 + weight * 0.8, # Line thickness based on weight
88-
}
89-
)
90-
arc_id += 1
91-
92-
arc_df = pd.DataFrame(arc_data)
72+
arc_df_chunk = pd.DataFrame(
73+
{"x": x_arc, "y": y_arc, "arc_id": arc_id, "size": 0.8 + weight * 0.7, "alpha": 0.30 + weight * 0.18}
74+
)
75+
arc_rows.append(arc_df_chunk)
9376

94-
# Create nodes dataframe
95-
node_df = pd.DataFrame({"x": x_positions, "y": [y_baseline] * n_nodes, "name": nodes})
77+
arc_df = pd.concat(arc_rows, ignore_index=True)
9678

97-
# Create label dataframe (below nodes)
98-
label_df = pd.DataFrame({"x": x_positions, "y": [y_baseline - 0.05] * n_nodes, "name": nodes})
79+
# Node and label dataframes
80+
node_df = pd.DataFrame({"x": x_positions, "y": [y_baseline] * n_nodes})
81+
label_df = pd.DataFrame({"x": x_positions, "y": [y_baseline - 0.03] * n_nodes, "name": nodes})
9982

100-
# Create the plot
83+
# Plot
10184
plot = (
10285
ggplot()
103-
# Draw arcs
104-
+ geom_path(arc_df, aes(x="x", y="y", group="arc_id", size="size"), color="#306998", alpha=0.6)
86+
+ geom_path(arc_df, aes(x="x", y="y", group="arc_id", size="size", alpha="alpha"), color="#306998")
10587
+ scale_size_identity()
106-
# Draw nodes
107-
+ geom_point(node_df, aes(x="x", y="y"), color="#FFD43B", size=10, stroke=1.5, fill="#FFD43B")
108-
# Add node labels
109-
+ geom_text(label_df, aes(x="x", y="y", label="name"), size=11, color="#306998", fontweight="bold", va="top")
110-
+ labs(title="Character Interactions · arc-basic · plotnine · pyplots.ai")
88+
+ scale_alpha_identity()
89+
+ geom_point(node_df, aes(x="x", y="y"), color="#306998", size=8, stroke=1.2, fill="white")
90+
+ geom_text(label_df, aes(x="x", y="y", label="name"), size=12, color="#2C3E50", fontweight="bold", va="top")
91+
+ coord_cartesian(xlim=(-0.05, 1.05))
92+
+ labs(title="Character Interactions \u00b7 arc-basic \u00b7 plotnine \u00b7 pyplots.ai")
11193
+ theme(
11294
figure_size=(16, 9),
113-
plot_title=element_text(size=24, ha="center"),
95+
plot_title=element_text(size=24, ha="center", weight="bold"),
96+
plot_margin=0.02,
11497
axis_title=element_blank(),
11598
axis_text=element_blank(),
11699
axis_ticks=element_blank(),
117100
panel_grid=element_blank(),
118-
panel_background=element_blank(),
119-
plot_background=element_blank(),
101+
panel_background=element_rect(fill="white", color="white"),
102+
plot_background=element_rect(fill="white", color="white"),
120103
legend_position="none",
121104
)
122105
)
123106

124-
# Save the plot
107+
# Save
125108
plot.save("plot.png", dpi=300, verbose=False)

plots/arc-basic/metadata/plotnine.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
library: plotnine
22
specification_id: arc-basic
33
created: '2025-12-23T08:49:49Z'
4-
updated: '2025-12-23T09:04:36Z'
5-
generated_by: claude-opus-4-5-20251101
4+
updated: '2026-02-23T12:00:00+00:00'
5+
generated_by: claude-opus-4-6
66
workflow_run: 20455963275
77
issue: 0
8-
python_version: 3.13.11
9-
library_version: 0.15.2
8+
python_version: '3.14.3'
9+
library_version: 0.15.3
1010
preview_url: https://storage.googleapis.com/pyplots-images/plots/arc-basic/plotnine/plot.png
1111
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/arc-basic/plotnine/plot_thumb.png
1212
preview_html: null
13-
quality_score: 91
13+
quality_score: null
1414
impl_tags:
1515
dependencies: []
1616
techniques:

0 commit comments

Comments
 (0)