Skip to content

Commit d22e29c

Browse files
feat(letsplot): implement column-stratigraphic
1 parent 4a54060 commit d22e29c

1 file changed

Lines changed: 151 additions & 0 deletions

File tree

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
"""pyplots.ai
2+
column-stratigraphic: Stratigraphic Column with Lithology Patterns
3+
Library: letsplot | Python 3.13
4+
Quality: pending | Created: 2026-03-15
5+
"""
6+
# ruff: noqa: F405
7+
8+
import os
9+
import shutil
10+
11+
import pandas as pd
12+
from lets_plot import * # noqa: F403
13+
14+
15+
LetsPlot.setup_html()
16+
17+
# Data - synthetic sedimentary section with 10 layers (depth increasing downward)
18+
layers = pd.DataFrame(
19+
{
20+
"top": [0, 15, 35, 55, 80, 110, 135, 165, 195, 230],
21+
"bottom": [15, 35, 55, 80, 110, 135, 165, 195, 230, 260],
22+
"lithology": [
23+
"Sandstone",
24+
"Shale",
25+
"Limestone",
26+
"Siltstone",
27+
"Sandstone",
28+
"Conglomerate",
29+
"Shale",
30+
"Limestone",
31+
"Siltstone",
32+
"Sandstone",
33+
],
34+
"formation": [
35+
"Basal Sand Fm",
36+
"Dark Shale Mbr",
37+
"Reef Limestone Fm",
38+
"Gray Silt Mbr",
39+
"Channel Sand Fm",
40+
"Gravel Bed Fm",
41+
"Marine Shale Fm",
42+
"Platform Carb Fm",
43+
"Tidal Flat Mbr",
44+
"Upper Sand Fm",
45+
],
46+
"age": [
47+
"Triassic",
48+
"Triassic",
49+
"Jurassic",
50+
"Jurassic",
51+
"Jurassic",
52+
"Cretaceous",
53+
"Cretaceous",
54+
"Cretaceous",
55+
"Paleogene",
56+
"Paleogene",
57+
],
58+
}
59+
)
60+
61+
layers["thickness"] = layers["bottom"] - layers["top"]
62+
layers["xmin"] = 0.0
63+
layers["xmax"] = 1.0
64+
65+
# Lithology color palette (earthy geological tones)
66+
lithology_colors = {
67+
"Sandstone": "#F2CC6B",
68+
"Shale": "#8B8B8B",
69+
"Limestone": "#5B9BD5",
70+
"Siltstone": "#B5A48B",
71+
"Conglomerate": "#D4726A",
72+
}
73+
lithology_order = ["Sandstone", "Shale", "Limestone", "Siltstone", "Conglomerate"]
74+
75+
# Build label data: formation names (right) + age labels (left)
76+
label_rows = []
77+
for _, row in layers.iterrows():
78+
mid_depth = (row["top"] + row["bottom"]) / 2
79+
label_rows.append({"x": 1.12, "y": mid_depth, "label": row["formation"]})
80+
81+
age_spans = {"Triassic": (0, 35), "Jurassic": (35, 110), "Cretaceous": (110, 195), "Paleogene": (195, 260)}
82+
for age_name, (age_top, age_bottom) in age_spans.items():
83+
label_rows.append({"x": -0.12, "y": (age_top + age_bottom) / 2, "label": age_name})
84+
85+
labels_df = pd.DataFrame(label_rows)
86+
87+
# Age boundary dashed lines
88+
age_boundary_depths = [35, 110, 195]
89+
boundaries_df = pd.DataFrame(
90+
{"x": [-0.02] * 3, "y": age_boundary_depths, "xend": [1.02] * 3, "yend": age_boundary_depths}
91+
)
92+
93+
# Plot
94+
plot = (
95+
ggplot()
96+
+ geom_rect(
97+
aes(xmin="xmin", xmax="xmax", ymin="top", ymax="bottom", fill="lithology"),
98+
data=layers,
99+
color="black",
100+
size=0.8,
101+
alpha=0.85,
102+
tooltips=layer_tooltips()
103+
.line("@lithology")
104+
.line("Depth: @top\u2013@bottom m")
105+
.line("Thickness: @thickness m")
106+
.line("Formation: @formation")
107+
.line("Age: @age"),
108+
)
109+
+ geom_segment(
110+
aes(x="x", y="y", xend="xend", yend="yend"),
111+
data=boundaries_df,
112+
linetype="dashed",
113+
color="#888888",
114+
size=0.7,
115+
show_legend=False,
116+
)
117+
+ geom_text(aes(x="x", y="y", label="label"), data=labels_df, size=10, color="#333333")
118+
+ scale_fill_manual(values=lithology_colors, name="Lithology", limits=lithology_order)
119+
+ scale_y_reverse()
120+
+ scale_x_continuous(limits=[-0.35, 1.85])
121+
+ labs(title="column-stratigraphic \u00b7 letsplot \u00b7 pyplots.ai", y="Depth (m)", x="")
122+
+ theme_minimal()
123+
+ theme(
124+
plot_title=element_text(size=24, face="bold"),
125+
axis_title_y=element_text(size=20),
126+
axis_title_x=element_blank(),
127+
axis_text_y=element_text(size=16),
128+
axis_text_x=element_blank(),
129+
axis_ticks_x=element_blank(),
130+
legend_title=element_text(size=16, face="bold"),
131+
legend_text=element_text(size=14),
132+
legend_position="bottom",
133+
panel_grid_major_x=element_blank(),
134+
panel_grid_minor_x=element_blank(),
135+
panel_grid_major_y=element_line(size=0.3, color="#dddddd"),
136+
panel_grid_minor_y=element_blank(),
137+
)
138+
+ ggsize(1600, 900)
139+
)
140+
141+
# Save
142+
ggsave(plot, "plot.png", scale=3)
143+
ggsave(plot, "plot.html")
144+
145+
# Move files from lets-plot-images to current directory
146+
if os.path.exists("lets-plot-images/plot.png"):
147+
shutil.move("lets-plot-images/plot.png", "plot.png")
148+
if os.path.exists("lets-plot-images/plot.html"):
149+
shutil.move("lets-plot-images/plot.html", "plot.html")
150+
if os.path.exists("lets-plot-images") and not os.listdir("lets-plot-images"):
151+
os.rmdir("lets-plot-images")

0 commit comments

Comments
 (0)