Skip to content
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c3a12c4
Add code for 3-D bar plot
yvonnefroehlich Dec 20, 2025
b3ab361
Remove execution permission
yvonnefroehlich Dec 20, 2025
a177004
Merge branch 'main' into add-gallery-3dbar
yvonnefroehlich Jan 5, 2026
9ba41bb
Merge branch 'main' into add-gallery-3dbar
yvonnefroehlich Jan 12, 2026
13284df
Use Position class
yvonnefroehlich Jan 12, 2026
712aee3
Add introduction text
yvonnefroehlich Jan 15, 2026
bfc3ed9
Add comments to codes
yvonnefroehlich Jan 15, 2026
b9aef30
Use tuple instead of lists
yvonnefroehlich Jan 15, 2026
eaa9d5c
Merge branch 'main' into add-gallery-3dbar
yvonnefroehlich Jan 15, 2026
f8fb0c1
Update examples/gallery/3d_plots/3d_bar.py
yvonnefroehlich Jan 16, 2026
aa0872a
Use zmin and zmax
yvonnefroehlich Jan 16, 2026
68fd801
Use grd2xyz without region
yvonnefroehlich Jan 16, 2026
9b079e1
Improve variable name 'grd2tab' to 'grd_df'
yvonnefroehlich Jan 16, 2026
5ac3c3b
Improve variable name 'grd2tab' to 'grd_df'
yvonnefroehlich Jan 16, 2026
074facb
Try smaller zsize and adjust colorbar offset
yvonnefroehlich Jan 16, 2026
55f8c23
Fix line length
yvonnefroehlich Jan 16, 2026
014474d
Improve comment for study region
yvonnefroehlich Jan 16, 2026
2b80bd6
Update introduction text
yvonnefroehlich Jan 19, 2026
d3ba8d4
Merge branch 'main' into add-gallery-3dbar
yvonnefroehlich Jan 19, 2026
d3ae5b9
Fix quotation mark
yvonnefroehlich Jan 19, 2026
d769f32
Add intro from GMT example
yvonnefroehlich Jan 21, 2026
b0c17b5
Improve comment on fourth column added for color-coding
yvonnefroehlich Jan 22, 2026
bc6b5fa
Merge branch 'main' into add-gallery-3dbar
yvonnefroehlich Jan 22, 2026
2e9ed08
Improve intorduction
yvonnefroehlich Jan 22, 2026
0e2e414
Merge branch 'main' into add-gallery-3dbar
yvonnefroehlich Jan 24, 2026
d0e0d8e
Improve introdcution text
yvonnefroehlich Jan 25, 2026
a8d3aa5
Improve introdcution text
yvonnefroehlich Jan 25, 2026
de65289
Remove blank line
yvonnefroehlich Jan 25, 2026
43c672e
Revert "Remove blank line"
yvonnefroehlich Jan 25, 2026
17d8024
Fix typos
yvonnefroehlich Jan 26, 2026
b942514
Fix examples/gallery/3d_plots/3d_bar.py
seisman Jan 26, 2026
20abab4
Fix styling
seisman Jan 26, 2026
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
69 changes: 69 additions & 0 deletions examples/gallery/3d_plots/3d_bar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""
3-D bar plot
============

A 3-D bar plot can be created from any collection of three-dimensional tabular data. The
data points can lie on a regular grid or be irregularly scattered. A special case is
creating such a 3-D bar plot based on a grid. This can be done in two steps:

1. Converting the grid into a table via :func:`pygmt.grd2xyz`, with columns "x", "y",
and "z" for longitude, latitude, and the quantity displayed by the grid,
respectively.
2. Plotting this table as bars in 3-D using :meth:`pygmt.Figure.plot3d`.

The bars can be outlined, and the fill can be one color or based on a quantity using a
colormap. For the latter, a fourth column needs to be added containing the values of the
quantity for the color-coding.
"""

# %%
import pygmt
from pygmt.params import Position

# Define a study area around northern Japan with large elevation changes
region = [141, 147, 36, 43]

# Download a grid for the Earth relief with a resolution of 10 arc-minutes
grid = pygmt.datasets.load_earth_relief(resolution="10m", region=region)

# Convert the grid into a pandas DataFrame, with columns for longitude ("x"), latitude
# ("y") and elevation ("z")
grd_df = pygmt.grd2xyz(grid=grid)
zmin = grd_df["z"].min() - 50
zmax = grd_df["z"].max() + 50

# Add a fourth column "color" for the quantity used for the color-coding of the bars,
# here we use the elevation ("z")
grd_df["color"] = grd_df["z"]

# Create a 3-D bar plot with color-coding
fig = pygmt.Figure()

fig.basemap(
region=[*region, zmin, zmax],
projection="M10c",
zsize="8c",
frame=["WSneZ", "xaf", "yag", "za1000f500+lElevation / m"],
perspective=(195, 30),
)

pygmt.makecpt(cmap="SCM/oleron", series=(zmin, zmax))
fig.plot3d(
data=grd_df,
# Use "o" to plot bars and give the desired size
# The base of the bars is set via "+b"
style=f"o0.34c+b{zmin}",
cmap=True,
pen="0.01p,gray30",
perspective=True,
)
fig.colorbar(
frame=["xa1000f500+lElevation", "y+lm"],
position=Position("TR", cstype="inside", offset=1.4),
orientation="vertical",
length=7,
move_text="label",
label_as_column=True,
)

fig.show()
Loading