Skip to content

Commit b562c96

Browse files
committed
update examples
1 parent ef7339f commit b562c96

8 files changed

+169
-28
lines changed
12.1 KB
Loading
20.9 KB
Loading
81.7 KB
Loading
109 KB
Loading

examples/plot_subduction_zones.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,20 @@ def plot_teeth(ax, lons, lats, polarity):
3030
x = [t["lon"] for t in tooth]
3131
y = [t["lat"] for t in tooth]
3232
# print(x)
33-
ax.fill(x, y, transform=ccrs.PlateCarree())
33+
ax.fill(
34+
x,
35+
y,
36+
facecolor="blue",
37+
edgecolor="blue",
38+
transform=ccrs.PlateCarree(),
39+
)
3440

3541

3642
def main(show=True):
3743
time = 0
3844
model_name = "Merdith2021"
3945

40-
ax = get_basemap_with_coastlines(model=model_name, time=time)
46+
fig, ax = get_basemap_with_coastlines(model=model_name, time=time)
4147

4248
model = plate_model.PlateModel(model_name)
4349

@@ -55,17 +61,24 @@ def main(show=True):
5561
if geom["type"] == "LineString":
5662
lats = [lon_lat[1] for lon_lat in geom["coordinates"]]
5763
lons = [lon_lat[0] for lon_lat in geom["coordinates"]]
58-
ax.plot(lons, lats, transform=ccrs.PlateCarree())
64+
ax.plot(lons, lats, transform=ccrs.PlateCarree(), color="blue")
5965
plot_teeth(ax, lons, lats, polarity)
6066

6167
elif geom["type"] == "MultiLineString":
6268
for line in geom["coordinates"]:
6369
lats = [lon_lat[1] for lon_lat in line]
6470
lons = [lon_lat[0] for lon_lat in line]
65-
ax.plot(lons, lats, transform=ccrs.PlateCarree())
71+
ax.plot(lons, lats, transform=ccrs.PlateCarree(), color="blue")
6672
plot_teeth(ax, lons, lats, polarity)
6773

68-
plt.title(f"{time} Ma", fontsize=20)
74+
plt.title(f"{time} Ma (Merdith2021)")
75+
76+
fig.text(
77+
0.5,
78+
0.03,
79+
"subduction zones with teeth",
80+
ha="center",
81+
)
6982

7083
if show:
7184
plt.show()
@@ -82,7 +95,17 @@ def get_basemap_with_coastlines(model="Muller2019", crs=ccrs.Robinson(), time=14
8295
ax = plt.axes(projection=crs)
8396

8497
ax.set_global()
85-
ax.gridlines()
98+
gl = ax.gridlines(
99+
crs=ccrs.PlateCarree(),
100+
draw_labels=True,
101+
color="grey",
102+
alpha=0.5,
103+
linestyle="--",
104+
)
105+
gl.top_labels = False
106+
gl.right_labels = False
107+
gl.xlabel_style = {"size": 7, "color": "gray"}
108+
gl.ylabel_style = {"size": 7, "color": "gray"}
86109

87110
ax.add_geometries(
88111
coastlines_shapely,
@@ -91,7 +114,7 @@ def get_basemap_with_coastlines(model="Muller2019", crs=ccrs.Robinson(), time=14
91114
edgecolor="none",
92115
alpha=0.5,
93116
)
94-
return ax
117+
return fig, ax
95118

96119

97120
def save_fig(filename):

examples/plot_topological_features.py

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,33 @@
1616
# micromamba run -n gplates-ws-example ./plot_topological_features.py
1717

1818

19-
def plot_lines(ax, lines, color="blue"):
19+
def plot_lines(ax, lines, color="blue", label=""):
2020
for line in lines:
2121
if isinstance(line, MultiLineString):
2222
for g in line.geoms:
23-
ax.plot(*g.xy, transform=ccrs.PlateCarree(), color=color)
23+
ax.plot(
24+
*g.xy,
25+
transform=ccrs.PlateCarree(),
26+
color=color,
27+
label=label,
28+
linewidth=0.7,
29+
)
2430
else:
25-
ax.plot(*line.xy, transform=ccrs.PlateCarree(), color=color)
31+
ax.plot(
32+
*line.xy,
33+
transform=ccrs.PlateCarree(),
34+
color=color,
35+
label=label,
36+
linewidth=0.7,
37+
)
2638

2739

2840
def main(show=True):
2941
model = PlateModel("Muller2019")
3042
time = 10
3143
topology_10 = model.get_topology(time)
3244

33-
mid_ccean_ridge = topology_10.get_features("MidOceanRidge", return_format="shapely")
45+
mid_ocean_ridge = topology_10.get_features("MidOceanRidge", return_format="shapely")
3446
transform = topology_10.get_features("Transform", return_format="shapely")
3547
fault = topology_10.get_features("Fault", return_format="shapely")
3648
subduction = topology_10.get_features("SubductionZone", return_format="shapely")
@@ -39,14 +51,45 @@ def main(show=True):
3951
ax = plt.axes(projection=ccrs.Robinson())
4052

4153
ax.set_global()
42-
ax.gridlines()
43-
44-
plot_lines(ax, mid_ccean_ridge, color="red")
45-
plot_lines(ax, transform, color="black")
46-
plot_lines(ax, fault, color="yellow")
47-
plot_lines(ax, subduction)
48-
49-
plt.title(f"{time} Ma")
54+
gl = ax.gridlines(
55+
crs=ccrs.PlateCarree(),
56+
draw_labels=True,
57+
color="grey",
58+
alpha=0.5,
59+
linestyle="--",
60+
)
61+
gl.top_labels = False
62+
gl.right_labels = False
63+
gl.xlabel_style = {"size": 7, "color": "gray"}
64+
gl.ylabel_style = {"size": 7, "color": "gray"}
65+
66+
plot_lines(ax, mid_ocean_ridge, color="red", label="mid-ocean ridge")
67+
plot_lines(ax, transform, color="black", label="transform")
68+
plot_lines(ax, fault, color="orange", label="fault")
69+
plot_lines(ax, subduction, label="subduction zone")
70+
71+
# plot the legend
72+
handles, labels = ax.get_legend_handles_labels()
73+
unique = [
74+
(h, l) for i, (h, l) in enumerate(zip(handles, labels)) if l not in labels[:i]
75+
]
76+
legend = plt.legend(
77+
*zip(*unique),
78+
title="Feature Types",
79+
prop={"size": 6},
80+
loc="lower right",
81+
bbox_to_anchor=(1.0, 0.9),
82+
)
83+
plt.setp(legend.get_title(), fontsize="xx-small")
84+
85+
plt.title(f"{time} Ma (Muller2019)")
86+
87+
fig.text(
88+
0.5,
89+
0.03,
90+
"topological features with different colours",
91+
ha="center",
92+
)
5093
if show:
5194
plt.show()
5295
else:

examples/plot_topological_plate_boundaries.py

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
import cartopy.crs as ccrs
66
import matplotlib.pyplot as plt
7-
from shapely.geometry import MultiLineString
7+
import numpy as np
8+
from shapely.geometry import MultiLineString, MultiPolygon, Polygon, shape
89

910
from gwspy import PlateModel
1011

@@ -21,21 +22,77 @@ def main(show=True):
2122
time = 10
2223
topology_10 = model.get_topology(time)
2324

24-
polylines = topology_10.get_plate_boundaries(return_format="shapely")
25+
_lines = topology_10.get_plate_boundaries()
26+
colors = []
27+
feature_types = []
28+
polylines = []
29+
color_map = {}
30+
for feature in _lines["features"]:
31+
s = shape(feature["geometry"])
32+
polylines.append(s)
33+
f_type = feature["properties"]["type"]
34+
feature_types.append(f_type)
35+
if f_type not in color_map:
36+
cc = list(np.random.choice(range(256), size=3) / 256)
37+
color_map[f_type] = cc
38+
else:
39+
cc = color_map[f_type]
40+
colors.append(cc)
41+
# if f_type == "gpml:TopologicalNetwork":
42+
# colors.append("green")
43+
44+
print(set(feature_types))
2545

2646
fig = plt.figure(figsize=(12, 6), dpi=120)
2747
ax = plt.axes(projection=ccrs.Robinson())
2848

2949
ax.set_global()
30-
ax.gridlines()
50+
gl = ax.gridlines(
51+
crs=ccrs.PlateCarree(),
52+
draw_labels=True,
53+
color="grey",
54+
alpha=0.5,
55+
linestyle="--",
56+
)
57+
gl.top_labels = False
58+
gl.right_labels = False
59+
gl.xlabel_style = {"size": 7, "color": "gray"}
60+
gl.ylabel_style = {"size": 7, "color": "gray"}
3161

32-
for line in polylines:
62+
# plot the lines
63+
for line, c, t in zip(polylines, colors, feature_types):
3364
if isinstance(line, MultiLineString):
3465
for g in line.geoms:
35-
ax.plot(*g.xy, transform=ccrs.PlateCarree(), color="blue")
66+
ax.plot(
67+
*g.xy, transform=ccrs.PlateCarree(), color=c, label=t, linewidth=0.7
68+
)
3669
else:
37-
ax.plot(*line.xy, transform=ccrs.PlateCarree(), color="blue")
38-
plt.title(f"{time} Ma")
70+
ax.plot(
71+
*line.xy, transform=ccrs.PlateCarree(), color=c, label=t, linewidth=0.7
72+
)
73+
# plot the legend
74+
handles, labels = ax.get_legend_handles_labels()
75+
unique = [
76+
(h, l) for i, (h, l) in enumerate(zip(handles, labels)) if l not in labels[:i]
77+
]
78+
legend = plt.legend(
79+
*zip(*unique),
80+
title="Feature Types",
81+
prop={"size": 6},
82+
loc="lower right",
83+
bbox_to_anchor=(1.14, 0.6),
84+
)
85+
plt.setp(legend.get_title(), fontsize="xx-small")
86+
87+
plt.title(f"{time} Ma (Muller2019)")
88+
89+
fig.text(
90+
0.5,
91+
0.03,
92+
"topological plate boundaries with random colours for each feature type",
93+
ha="center",
94+
)
95+
3996
if show:
4097
plt.show()
4198
else:

examples/plot_topological_plate_polygons.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,17 @@ def main(show=True):
6464
ax = plt.axes(projection=ccrs.Robinson())
6565

6666
ax.set_global()
67-
ax.gridlines()
67+
gl = ax.gridlines(
68+
crs=ccrs.PlateCarree(),
69+
draw_labels=True,
70+
color="grey",
71+
alpha=0.5,
72+
linestyle="--",
73+
)
74+
gl.top_labels = False
75+
gl.right_labels = False
76+
gl.xlabel_style = {"size": 7, "color": "gray"}
77+
gl.ylabel_style = {"size": 7, "color": "gray"}
6878

6979
# fill the polygons with grey
7080
ax.add_geometries(
@@ -100,7 +110,15 @@ def main(show=True):
100110
bbox_to_anchor=(1.1, 0.9),
101111
)
102112
plt.setp(legend.get_title(), fontsize="xx-small")
103-
plt.title(f"{time} Ma")
113+
plt.title(f"{time} Ma (Muller2019)")
114+
115+
fig.text(
116+
0.5,
117+
0.03,
118+
"topological closed plate boundary and network",
119+
ha="center",
120+
)
121+
104122
if show:
105123
plt.show()
106124
else:

0 commit comments

Comments
 (0)