Skip to content

Commit 341c5d2

Browse files
feat(matplotlib): implement tree-phylogenetic (#3110)
## Implementation: `tree-phylogenetic` - matplotlib Implements the **matplotlib** version of `tree-phylogenetic`. **File:** `plots/tree-phylogenetic/implementations/matplotlib.py` **Parent Issue:** #3070 --- :robot: *[impl-generate workflow](https://github.com/MarkusNeusinger/pyplots/actions/runs/20620332010)* --------- 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 6a4538a commit 341c5d2

2 files changed

Lines changed: 145 additions & 0 deletions

File tree

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
""" pyplots.ai
2+
tree-phylogenetic: Phylogenetic Tree Diagram
3+
Library: matplotlib 3.10.8 | Python 3.13.11
4+
Quality: 91/100 | Created: 2025-12-31
5+
"""
6+
7+
import matplotlib.pyplot as plt
8+
9+
10+
# Primate phylogenetic tree - pre-computed coordinates
11+
# Each leaf: (name, y_position, x_end) where x_end is total distance from root
12+
# Species ordered by evolutionary grouping (top to bottom)
13+
species = [
14+
("Galago", 0, 0.24),
15+
("Tarsier", 1, 0.24),
16+
("Lemur", 2, 0.18),
17+
("Spider Monkey", 3, 0.20),
18+
("Capuchin", 4, 0.19),
19+
("Baboon", 5, 0.18),
20+
("Rhesus Macaque", 6, 0.18),
21+
("Gibbon", 7, 0.16),
22+
("Orangutan", 8, 0.15),
23+
("Gorilla", 9, 0.14),
24+
("Chimpanzee", 10, 0.13),
25+
("Human", 11, 0.13),
26+
]
27+
28+
# Branch structure: each branch is (x1, y1, x2, y2, color)
29+
# Horizontal branches (to tips)
30+
branch_color = "#306998"
31+
yellow = "#FFD43B"
32+
green = "#5A9C5A"
33+
34+
# Pre-computed branch segments for the phylogenetic tree
35+
# Format: (x_start, y_start, x_end, y_end, color)
36+
branches = [
37+
# Root split (Prosimians vs Simians)
38+
(0, 5.5, 0.05, 5.5, branch_color), # Root to split
39+
(0.05, 1, 0.05, 5.5, branch_color), # Vertical at root
40+
(0.05, 1, 0.05, 10, branch_color), # Vertical to Simians
41+
# Prosimians clade
42+
(0.05, 1, 0.08, 1, green), # To Prosimians node
43+
(0.08, 0.5, 0.08, 2, green), # Prosimians vertical
44+
(0.08, 0.5, 0.10, 0.5, green), # To Lorisoids
45+
(0.10, 0, 0.10, 1, green), # Lorisoids vertical
46+
(0.10, 0, 0.24, 0, green), # To Galago
47+
(0.10, 1, 0.24, 1, green), # To Tarsier
48+
(0.08, 2, 0.18, 2, green), # To Lemur
49+
# Simians main branch
50+
(0.05, 10, 0.08, 10, branch_color), # To Simians node
51+
(0.08, 5.5, 0.08, 10, branch_color), # Simians vertical
52+
# Apes clade
53+
(0.08, 10, 0.10, 10, branch_color), # To Apes
54+
(0.10, 8.5, 0.10, 10, branch_color), # Apes vertical
55+
# African Apes
56+
(0.10, 10, 0.11, 10, branch_color), # To African Apes
57+
(0.11, 9.5, 0.11, 11, branch_color), # African Apes vertical
58+
(0.11, 9, 0.14, 9, branch_color), # To Gorilla
59+
(0.11, 10.5, 0.12, 10.5, branch_color), # To Hominini
60+
(0.12, 10, 0.12, 11, branch_color), # Hominini vertical
61+
(0.12, 10, 0.13, 10, branch_color), # To Chimpanzee
62+
(0.12, 11, 0.13, 11, branch_color), # To Human
63+
# Asian Apes
64+
(0.10, 8.5, 0.13, 8.5, branch_color), # To Asian Apes
65+
(0.13, 7, 0.13, 8, branch_color), # Asian Apes vertical
66+
(0.13, 7, 0.16, 7, branch_color), # To Gibbon
67+
(0.13, 8, 0.15, 8, branch_color), # To Orangutan
68+
# Monkeys clade
69+
(0.08, 5.5, 0.12, 5.5, yellow), # To Monkeys
70+
(0.12, 3.5, 0.12, 5.5, yellow), # Monkeys vertical
71+
# Old World Monkeys
72+
(0.12, 5.5, 0.14, 5.5, yellow), # To Old World
73+
(0.14, 5, 0.14, 6, yellow), # OW vertical
74+
(0.14, 5, 0.18, 5, yellow), # To Baboon
75+
(0.14, 6, 0.18, 6, yellow), # To Rhesus
76+
# New World Monkeys
77+
(0.12, 3.5, 0.15, 3.5, yellow), # To New World
78+
(0.15, 3, 0.15, 4, yellow), # NW vertical
79+
(0.15, 3, 0.20, 3, yellow), # To Spider Monkey
80+
(0.15, 4, 0.19, 4, yellow), # To Capuchin
81+
]
82+
83+
# Create figure
84+
fig, ax = plt.subplots(figsize=(16, 9))
85+
86+
# Draw all branches
87+
for x1, y1, x2, y2, color in branches:
88+
ax.plot([x1, x2], [y1, y2], color=color, linewidth=2.5, solid_capstyle="round")
89+
90+
# Draw species labels
91+
for name, y, x in species:
92+
ax.plot(x, y, "o", color=branch_color, markersize=8)
93+
ax.text(x + 0.008, y, name, va="center", ha="left", fontsize=16, fontweight="medium")
94+
95+
# Style the plot
96+
ax.set_xlabel("Evolutionary Distance (substitutions per site)", fontsize=20)
97+
ax.set_title("Primate Evolution · tree-phylogenetic · matplotlib · pyplots.ai", fontsize=24)
98+
99+
# Set axis limits
100+
ax.set_xlim(-0.02, 0.38)
101+
ax.set_ylim(-1, 12.5)
102+
103+
# Style ticks
104+
ax.tick_params(axis="x", labelsize=16)
105+
ax.tick_params(axis="y", left=False, labelleft=False)
106+
107+
# Add subtle grid on x-axis only
108+
ax.grid(True, axis="x", alpha=0.3, linestyle="--")
109+
110+
# Remove spines
111+
ax.spines["top"].set_visible(False)
112+
ax.spines["right"].set_visible(False)
113+
ax.spines["left"].set_visible(False)
114+
115+
# Add scale bar
116+
ax.plot([0, 0.05], [-0.5, -0.5], color="#333333", linewidth=3, solid_capstyle="butt")
117+
ax.text(0.025, -0.8, "0.05", ha="center", va="top", fontsize=14, color="#333333")
118+
119+
plt.tight_layout()
120+
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
library: matplotlib
2+
specification_id: tree-phylogenetic
3+
created: '2025-12-31T13:56:05Z'
4+
updated: '2025-12-31T14:07:51Z'
5+
generated_by: claude-opus-4-5-20251101
6+
workflow_run: 20620332010
7+
issue: 3070
8+
python_version: 3.13.11
9+
library_version: 3.10.8
10+
preview_url: https://storage.googleapis.com/pyplots-images/plots/tree-phylogenetic/matplotlib/plot.png
11+
preview_thumb: https://storage.googleapis.com/pyplots-images/plots/tree-phylogenetic/matplotlib/plot_thumb.png
12+
preview_html: null
13+
quality_score: 91
14+
review:
15+
strengths:
16+
- Excellent clade coloring with three distinct, colorblind-safe colors (blue, yellow,
17+
green) representing apes, monkeys, and prosimians
18+
- Clean, readable phylogenetic tree structure with proper proportional branch lengths
19+
- Well-formatted title following exact spec convention
20+
- Scale bar included for reference (0.05 units)
21+
- Scientifically accurate primate phylogeny with correct evolutionary groupings
22+
- Clean code structure with pre-computed coordinates for clarity
23+
weaknesses:
24+
- Missing legend to explain the meaning of the three clade colors (blue=apes, yellow=monkeys,
25+
green=prosimians)

0 commit comments

Comments
 (0)