Skip to content

Commit c3a12c4

Browse files
Add code for 3-D bar plot
1 parent 74b3cf7 commit c3a12c4

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
3-D bar plot
3+
============
4+
Based on GMT EXAMPLE 08
5+
https://docs.generic-mapping-tools.org/6.6/gallery/ex08.html
6+
Convert grid to table: :func:`pygmt.grd2xyz`
7+
Plot in 3-D via bars: meth:`pygmt.Figure.plot3d`
8+
"""
9+
10+
# %%
11+
import pygmt
12+
13+
region = [141, 147, 36, 43]
14+
grd2tab = pygmt.grd2xyz("@earth_relief_10m", region=region)
15+
grd2tab["color"] = grd2tab["z"]
16+
z_min = grd2tab["z"].min() - 50
17+
z_max = grd2tab["z"].max() + 50
18+
19+
fig = pygmt.Figure()
20+
21+
fig.basemap(
22+
region=[*region, z_min, z_max],
23+
projection="M10c",
24+
zsize="10c",
25+
perspective=[195, 30],
26+
frame=["WSneZ", "xaf", "yag", "za1000f500+lElevation / m"],
27+
)
28+
29+
pygmt.makecpt(cmap="SCM/oleron", series=[z_min, z_max])
30+
fig.plot3d(
31+
data=grd2tab,
32+
cmap=True,
33+
pen="0.01p,gray30",
34+
style=f"o0.34c+b{z_min}", # bars o, base +b
35+
perspective=True,
36+
)
37+
fig.colorbar(frame="xa1000f500+lElevation / m", position="jTR+o1.8c+v+w7c+ml")
38+
39+
fig.show()

0 commit comments

Comments
 (0)