Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
80 changes: 52 additions & 28 deletions plots/arc-basic/implementations/matplotlib.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
""" pyplots.ai
"""pyplots.ai
arc-basic: Basic Arc Diagram
Library: matplotlib 3.10.8 | Python 3.13.11
Quality: 91/100 | Created: 2025-12-23
Library: matplotlib 3.10.8 | Python 3.14.3
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.

The header quality score is incomplete with "Quality: /100" missing the actual score value. Based on the metadata file showing quality_score as null, this should either be removed entirely or show a placeholder like "Quality: pending/100" to match the pattern seen in other implementations.

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

Copilot uses AI. Check for mistakes.
"""

import matplotlib.cm as cm
import matplotlib.colors as mcolors
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
import numpy as np


# Data: Character interactions in a story chapter
np.random.seed(42)

nodes = ["Alice", "Bob", "Carol", "David", "Eve", "Frank", "Grace", "Henry", "Iris", "Jack"]
n_nodes = len(nodes)

Expand All @@ -34,62 +34,86 @@
(8, 9, 2), # Iris-Jack
]

# Create plot
weights = [w for _, _, w in edges]
weight_min, weight_max = min(weights), max(weights)

# Colormap: weight mapped to blue palette (truncated to avoid near-white)
norm = mcolors.Normalize(vmin=weight_min - 0.8, vmax=weight_max + 0.3)
cmap = cm.Blues

# Plot
fig, ax = plt.subplots(figsize=(16, 9))

# Node positions along x-axis
x_positions = np.linspace(0.05, 0.95, n_nodes)
y_baseline = 0.15
x_positions = np.linspace(0.05, 0.92, n_nodes)
y_baseline = 0.10

# Draw arcs
for start, end, weight in edges:
# Draw arcs (lighter weights first so strong connections render on top)
for start, end, weight in sorted(edges, key=lambda e: e[2]):
x_start = x_positions[start]
x_end = x_positions[end]

# Arc height proportional to distance between nodes
distance = abs(end - start)
height = 0.07 * distance
height = 0.06 * distance

# Center and width of the arc
x_center = (x_start + x_end) / 2
arc_width = abs(x_end - x_start)

# Arc thickness based on weight
linewidth = 2.0 + weight * 1.2
# Thickness and color both encode weight
linewidth = 1.5 + weight * 1.5
color = cmap(norm(weight))

# Semi-transparent arcs
alpha = 0.55

# Create arc using Arc patch
arc = mpatches.Arc(
(x_center, y_baseline),
width=arc_width,
height=height * 2,
angle=0,
theta1=0,
theta2=180,
color="#306998",
color=color,
linewidth=linewidth,
alpha=alpha,
alpha=0.75,
)
ax.add_patch(arc)

# Draw nodes
ax.scatter(x_positions, [y_baseline] * n_nodes, s=500, c="#FFD43B", edgecolors="#306998", linewidths=2.5, zorder=5)

# Add node labels
# Node labels
for x, name in zip(x_positions, nodes, strict=True):
ax.text(x, y_baseline - 0.06, name, ha="center", va="top", fontsize=16, fontweight="bold", color="#306998")
ax.text(x, y_baseline - 0.045, name, ha="center", va="top", fontsize=16, fontweight="bold", color="#306998")

# Weight colorbar (distinctive matplotlib feature)
tick_norm = mcolors.Normalize(vmin=weight_min, vmax=weight_max)
sm = cm.ScalarMappable(cmap=cmap, norm=tick_norm)
sm.set_array([])
cbar = fig.colorbar(sm, ax=ax, shrink=0.45, aspect=15, pad=0.02)
cbar.set_label("Connection Strength", fontsize=16)
cbar.set_ticks([1, 2, 3])
cbar.ax.tick_params(labelsize=14)

# Baseline indicator (thin horizontal line for visual grounding)
ax.plot(
[x_positions[0] - 0.02, x_positions[-1] + 0.02],
[y_baseline, y_baseline],
color="#306998",
linewidth=0.8,
alpha=0.25,
zorder=1,
)

# Styling
ax.set_xlim(-0.02, 1.02)
ax.set_ylim(-0.05, 0.85)
ax.set_aspect("equal")

# Remove axes
ax.set_xlim(-0.02, 0.98)
ax.set_ylim(-0.07, 0.68)
ax.axis("off")

ax.set_title("Character Interactions · arc-basic · matplotlib · pyplots.ai", fontsize=24, pad=20)
ax.set_title(
"Character Interactions \u00b7 arc-basic \u00b7 matplotlib \u00b7 pyplots.ai",
fontsize=24,
fontweight="medium",
pad=20,
)

plt.tight_layout()
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
8 changes: 4 additions & 4 deletions plots/arc-basic/metadata/matplotlib.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
library: matplotlib
specification_id: arc-basic
created: '2025-12-23T08:48:38Z'
updated: '2025-12-23T09:04:24Z'
generated_by: claude-opus-4-5-20251101
updated: '2026-02-23T12:00:00+00:00'
generated_by: claude-opus-4-6
workflow_run: 20455960794
issue: 0
python_version: 3.13.11
python_version: '3.14.3'
library_version: 3.10.8
preview_url: https://storage.googleapis.com/pyplots-images/plots/arc-basic/matplotlib/plot.png
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/arc-basic/matplotlib/plot_thumb.png
preview_html: null
quality_score: 91
quality_score: null
impl_tags:
dependencies: []
techniques:
Expand Down
1 change: 1 addition & 0 deletions plots/arc-basic/specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ An arc diagram arranges nodes along a single horizontal line and draws connectio
- `edges` (list of tuples) - Pairs of node indices or names indicating connections
- `weights` (numeric, optional) - Edge weights affecting arc thickness or height
- Size: 10-50 nodes typical for readability
- Example: Character interactions in a novel — nodes as characters, edges as dialogue exchanges

## Notes

Expand Down
6 changes: 4 additions & 2 deletions plots/arc-basic/specification.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: Basic Arc Diagram

# Specification tracking
created: 2025-12-15T20:43:43Z
updated: 2025-12-15T20:43:43Z
updated: 2026-02-23T12:00:00Z
issue: 991
suggested: MarkusNeusinger

Expand All @@ -18,8 +18,10 @@ tags:
data_type:
- network
- relational
- categorical
- ordinal
domain:
- general
features:
- basic
- connection-visualization
- 2d
Loading