From c3a12c4e4acbce8f87b7fe73aaa7e3f1dbc3782e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Sat, 20 Dec 2025 18:47:57 +0100 Subject: [PATCH 01/26] Add code for 3-D bar plot --- examples/gallery/3d_plots/3d_bar.py | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 examples/gallery/3d_plots/3d_bar.py diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py new file mode 100755 index 00000000000..3f38439e0e2 --- /dev/null +++ b/examples/gallery/3d_plots/3d_bar.py @@ -0,0 +1,39 @@ +""" +3-D bar plot +============ +Based on GMT EXAMPLE 08 +https://docs.generic-mapping-tools.org/6.6/gallery/ex08.html +Convert grid to table: :func:`pygmt.grd2xyz` +Plot in 3-D via bars: meth:`pygmt.Figure.plot3d` +""" + +# %% +import pygmt + +region = [141, 147, 36, 43] +grd2tab = pygmt.grd2xyz("@earth_relief_10m", region=region) +grd2tab["color"] = grd2tab["z"] +z_min = grd2tab["z"].min() - 50 +z_max = grd2tab["z"].max() + 50 + +fig = pygmt.Figure() + +fig.basemap( + region=[*region, z_min, z_max], + projection="M10c", + zsize="10c", + perspective=[195, 30], + frame=["WSneZ", "xaf", "yag", "za1000f500+lElevation / m"], +) + +pygmt.makecpt(cmap="SCM/oleron", series=[z_min, z_max]) +fig.plot3d( + data=grd2tab, + cmap=True, + pen="0.01p,gray30", + style=f"o0.34c+b{z_min}", # bars o, base +b + perspective=True, +) +fig.colorbar(frame="xa1000f500+lElevation / m", position="jTR+o1.8c+v+w7c+ml") + +fig.show() From b3ab361a595af6a03ced35eb6379d5051bdbc85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Sat, 20 Dec 2025 18:58:35 +0100 Subject: [PATCH 02/26] Remove execution permission --- examples/gallery/3d_plots/3d_bar.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 examples/gallery/3d_plots/3d_bar.py diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py old mode 100755 new mode 100644 From 13284dfaf5c226ac6c2646f80a675156fdf69afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Mon, 12 Jan 2026 18:07:54 +0100 Subject: [PATCH 03/26] Use Position class --- examples/gallery/3d_plots/3d_bar.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 3f38439e0e2..c1150ac6335 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -1,14 +1,19 @@ """ 3-D bar plot ============ + Based on GMT EXAMPLE 08 + https://docs.generic-mapping-tools.org/6.6/gallery/ex08.html + Convert grid to table: :func:`pygmt.grd2xyz` -Plot in 3-D via bars: meth:`pygmt.Figure.plot3d` + +Plot in 3-D via bars: :meth:`pygmt.Figure.plot3d` """ # %% import pygmt +from pygmt.params import Position region = [141, 147, 36, 43] grd2tab = pygmt.grd2xyz("@earth_relief_10m", region=region) @@ -34,6 +39,14 @@ style=f"o0.34c+b{z_min}", # bars o, base +b perspective=True, ) -fig.colorbar(frame="xa1000f500+lElevation / m", position="jTR+o1.8c+v+w7c+ml") +fig.colorbar( + frame=["xa1000f500+lElevation", "y+lm"], + # position="jTR+o1.8c+v+w7c+ml", + position=Position("TR", cstype="inside", offset=1.8), + orientation="vertical", + length=7, + move_text="label", + label_as_column=True, +) fig.show() From 712aee39bc17e6f8329d12c54c7cd1d8178c7602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 15 Jan 2026 10:43:20 +0100 Subject: [PATCH 04/26] Add introduction text --- examples/gallery/3d_plots/3d_bar.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index c1150ac6335..839e8fde488 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -2,13 +2,9 @@ 3-D bar plot ============ -Based on GMT EXAMPLE 08 - -https://docs.generic-mapping-tools.org/6.6/gallery/ex08.html - -Convert grid to table: :func:`pygmt.grd2xyz` - -Plot in 3-D via bars: :meth:`pygmt.Figure.plot3d` +A 3-D bar plot of a grid can be created in two steps: (i) convert the grid to a table +via :func:`pygmt.grd2xyz` and (ii) plot this table as bars in 3-D using +:meth:`pygmt.Figure.plot3d`. """ # %% From bfc3ed909dfc95c7d05141a150269761d811a46f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 15 Jan 2026 11:01:40 +0100 Subject: [PATCH 05/26] Add comments to codes --- examples/gallery/3d_plots/3d_bar.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 839e8fde488..f04303170ca 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -2,42 +2,52 @@ 3-D bar plot ============ -A 3-D bar plot of a grid can be created in two steps: (i) convert the grid to a table +A 3-D bar plot of a grid can be created in two steps: (i) convert the grid into a table via :func:`pygmt.grd2xyz` and (ii) plot this table as bars in 3-D using -:meth:`pygmt.Figure.plot3d`. +:meth:`pygmt.Figure.plot3d`. The bars can be outlined, and the fill can be one color or +based on a quantity using a colormap. """ # %% import pygmt from pygmt.params import Position +# Define a study area with huge elevation changes region = [141, 147, 36, 43] -grd2tab = pygmt.grd2xyz("@earth_relief_10m", region=region) + +# 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 table and add a column "color" for the quantity used for the +# color-coding of the bars, here the elevation ("z") +grd2tab = pygmt.grd2xyz(grid=grid, region=region) grd2tab["color"] = grd2tab["z"] z_min = grd2tab["z"].min() - 50 z_max = grd2tab["z"].max() + 50 +# Create a 3-D bar plot with color-coding fig = pygmt.Figure() fig.basemap( region=[*region, z_min, z_max], projection="M10c", zsize="10c", - perspective=[195, 30], frame=["WSneZ", "xaf", "yag", "za1000f500+lElevation / m"], + perspective=[195, 30], ) pygmt.makecpt(cmap="SCM/oleron", series=[z_min, z_max]) fig.plot3d( data=grd2tab, + # Use "o" to plot bars and give the desired size + # The base of the bars is set via "+b" + style=f"o0.34c+b{z_min}", cmap=True, pen="0.01p,gray30", - style=f"o0.34c+b{z_min}", # bars o, base +b perspective=True, ) fig.colorbar( frame=["xa1000f500+lElevation", "y+lm"], - # position="jTR+o1.8c+v+w7c+ml", position=Position("TR", cstype="inside", offset=1.8), orientation="vertical", length=7, From b9aef301ec934830ac8ca467f07bacc05570a926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 15 Jan 2026 15:10:04 +0100 Subject: [PATCH 06/26] Use tuple instead of lists --- examples/gallery/3d_plots/3d_bar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index f04303170ca..fe5df9f9139 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -33,10 +33,10 @@ projection="M10c", zsize="10c", frame=["WSneZ", "xaf", "yag", "za1000f500+lElevation / m"], - perspective=[195, 30], + perspective=(195, 30), ) -pygmt.makecpt(cmap="SCM/oleron", series=[z_min, z_max]) +pygmt.makecpt(cmap="SCM/oleron", series=(z_min, z_max)) fig.plot3d( data=grd2tab, # Use "o" to plot bars and give the desired size From f8fb0c1047ac415cb22956b264c6a90ac274c2ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Fri, 16 Jan 2026 10:28:52 +0100 Subject: [PATCH 07/26] Update examples/gallery/3d_plots/3d_bar.py Co-authored-by: Dongdong Tian --- examples/gallery/3d_plots/3d_bar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index fe5df9f9139..3d26ace6a74 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -22,8 +22,8 @@ # color-coding of the bars, here the elevation ("z") grd2tab = pygmt.grd2xyz(grid=grid, region=region) grd2tab["color"] = grd2tab["z"] -z_min = grd2tab["z"].min() - 50 -z_max = grd2tab["z"].max() + 50 +zmin = grd2tab["z"].min() - 50 +zmax = grd2tab["z"].max() + 50 # Create a 3-D bar plot with color-coding fig = pygmt.Figure() From aa0872a6480a67439f7f2f7cb9686bfac558ceb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 16 Jan 2026 10:32:04 +0100 Subject: [PATCH 08/26] Use zmin and zmax --- examples/gallery/3d_plots/3d_bar.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 3d26ace6a74..d5d7f992fcf 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -29,19 +29,19 @@ fig = pygmt.Figure() fig.basemap( - region=[*region, z_min, z_max], + region=[*region, zmin, zmax], projection="M10c", zsize="10c", frame=["WSneZ", "xaf", "yag", "za1000f500+lElevation / m"], perspective=(195, 30), ) -pygmt.makecpt(cmap="SCM/oleron", series=(z_min, z_max)) +pygmt.makecpt(cmap="SCM/oleron", series=(zmin, zmax)) fig.plot3d( data=grd2tab, # Use "o" to plot bars and give the desired size # The base of the bars is set via "+b" - style=f"o0.34c+b{z_min}", + style=f"o0.34c+b{zmin}", cmap=True, pen="0.01p,gray30", perspective=True, From 68fd8019f645ecb7d968e34714ebf105a2e72dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Fri, 16 Jan 2026 10:34:23 +0100 Subject: [PATCH 09/26] Use grd2xyz without region Co-authored-by: Dongdong Tian --- examples/gallery/3d_plots/3d_bar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index d5d7f992fcf..7a1c0367ece 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -20,7 +20,7 @@ # Convert the grid into a table and add a column "color" for the quantity used for the # color-coding of the bars, here the elevation ("z") -grd2tab = pygmt.grd2xyz(grid=grid, region=region) +grd2tab = pygmt.grd2xyz(grid=grid) grd2tab["color"] = grd2tab["z"] zmin = grd2tab["z"].min() - 50 zmax = grd2tab["z"].max() + 50 From 9b079e1a425639ae8b96702d8baea1142d1bdbb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 16 Jan 2026 10:37:16 +0100 Subject: [PATCH 10/26] Improve variable name 'grd2tab' to 'grd_df' --- examples/gallery/3d_plots/3d_bar.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 7a1c0367ece..157e3cec5e3 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -18,12 +18,12 @@ # 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 table and add a column "color" for the quantity used for the -# color-coding of the bars, here the elevation ("z") -grd2tab = pygmt.grd2xyz(grid=grid) -grd2tab["color"] = grd2tab["z"] -zmin = grd2tab["z"].min() - 50 -zmax = grd2tab["z"].max() + 50 +# Convert the grid into a pandas DataFrame and add a column "color" for the quantity used +# for the color-coding of the bars, here the elevation ("z") +grd_df = pygmt.grd2xyz(grid=grid) +grd_df["color"] = grd2tab["z"] +zmin = grd_df["z"].min() - 50 +zmax = grd_df["z"].max() + 50 # Create a 3-D bar plot with color-coding fig = pygmt.Figure() @@ -38,7 +38,7 @@ pygmt.makecpt(cmap="SCM/oleron", series=(zmin, zmax)) fig.plot3d( - data=grd2tab, + 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}", From 5ac3c3b4c487e9349fe1a20cfab2e74fbcfd75de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 16 Jan 2026 10:41:44 +0100 Subject: [PATCH 11/26] Improve variable name 'grd2tab' to 'grd_df' --- examples/gallery/3d_plots/3d_bar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 157e3cec5e3..1cd0bb794a2 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -21,7 +21,7 @@ # Convert the grid into a pandas DataFrame and add a column "color" for the quantity used # for the color-coding of the bars, here the elevation ("z") grd_df = pygmt.grd2xyz(grid=grid) -grd_df["color"] = grd2tab["z"] +grd_df["color"] = grd_df["z"] zmin = grd_df["z"].min() - 50 zmax = grd_df["z"].max() + 50 From 074facb06030320d899d31397535b8e52ff2fe52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 16 Jan 2026 10:42:24 +0100 Subject: [PATCH 12/26] Try smaller zsize and adjust colorbar offset --- examples/gallery/3d_plots/3d_bar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 1cd0bb794a2..04b9c20c190 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -31,7 +31,7 @@ fig.basemap( region=[*region, zmin, zmax], projection="M10c", - zsize="10c", + zsize="8c", frame=["WSneZ", "xaf", "yag", "za1000f500+lElevation / m"], perspective=(195, 30), ) @@ -48,7 +48,7 @@ ) fig.colorbar( frame=["xa1000f500+lElevation", "y+lm"], - position=Position("TR", cstype="inside", offset=1.8), + position=Position("TR", cstype="inside", offset=1.4), orientation="vertical", length=7, move_text="label", From 55f8c23761978dcf0f1847dc433ef1e7eb7efcc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 16 Jan 2026 10:52:53 +0100 Subject: [PATCH 13/26] Fix line length --- examples/gallery/3d_plots/3d_bar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 04b9c20c190..a462e6a7d36 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -18,8 +18,8 @@ # 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 and add a column "color" for the quantity used -# for the color-coding of the bars, here the elevation ("z") +# Convert the grid into a pandas DataFrame and add a column "color" for the quantity +# used for the color-coding of the bars, here the elevation ("z") grd_df = pygmt.grd2xyz(grid=grid) grd_df["color"] = grd_df["z"] zmin = grd_df["z"].min() - 50 From 014474db6b5ce7a4cb38923d3be62a27f87be706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Fri, 16 Jan 2026 22:39:44 +0100 Subject: [PATCH 14/26] Improve comment for study region --- examples/gallery/3d_plots/3d_bar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index a462e6a7d36..12e5a1218da 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -12,7 +12,7 @@ import pygmt from pygmt.params import Position -# Define a study area with huge elevation changes +# 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 From 2b80bd6a5cb8a87137d92b1135044b47aa2c2e4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Mon, 19 Jan 2026 21:32:18 +0100 Subject: [PATCH 15/26] Update introduction text --- examples/gallery/3d_plots/3d_bar.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 12e5a1218da..17ee96723ad 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -2,10 +2,17 @@ 3-D bar plot ============ +TODO improve introduction + A 3-D bar plot of a grid can be created in two steps: (i) convert the grid into a table via :func:`pygmt.grd2xyz` and (ii) plot 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. + +We can create a 3-D bar plot for any collection of XYZ points, whether they lie on a +regular grid or are irregularly scattered. Therefore, it’s clearer to start with a +general description of the 3-D bar plot itself and then mention that, as a special +case, we can convert a grid into XYZ and visualize it with the same routine. """ # %% From d3ae5b9a068d87818041a172012127a8130299c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Mon, 19 Jan 2026 21:35:52 +0100 Subject: [PATCH 16/26] Fix quotation mark --- examples/gallery/3d_plots/3d_bar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 17ee96723ad..2cc8e8a7ac8 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -10,7 +10,7 @@ based on a quantity using a colormap. We can create a 3-D bar plot for any collection of XYZ points, whether they lie on a -regular grid or are irregularly scattered. Therefore, it’s clearer to start with a +regular grid or are irregularly scattered. Therefore, it's clearer to start with a general description of the 3-D bar plot itself and then mention that, as a special case, we can convert a grid into XYZ and visualize it with the same routine. """ From d769f32406abc61fe808617f39af441c821069b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Wed, 21 Jan 2026 13:11:06 +0100 Subject: [PATCH 17/26] Add intro from GMT example --- examples/gallery/3d_plots/3d_bar.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 2cc8e8a7ac8..d7042bfef1a 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -13,6 +13,13 @@ regular grid or are irregularly scattered. Therefore, it's clearer to start with a general description of the 3-D bar plot itself and then mention that, as a special case, we can convert a grid into XYZ and visualize it with the same routine. + +The program plot3d allows us to plot three-dimensional symbols, including columnar plots. +As a simple demonstration, we will convert a gridded netCDF of bathymetry into an ASCII +xyz table and use the height information to draw a 2-D histogram in a 3-D perspective +view. We also use the height information to set to color of each column via a CPT file. +Our gridded bathymetry file is the 5 arc-minute global relief. Depth ranges from -5000 +meter to sea-level. We produce the Figure by running this script. """ # %% From b0c17b5783b78d29a2e01e462ce1e7d5222ecc6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 22 Jan 2026 21:43:20 +0100 Subject: [PATCH 18/26] Improve comment on fourth column added for color-coding --- examples/gallery/3d_plots/3d_bar.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index d7042bfef1a..20a7d6bf931 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -32,13 +32,16 @@ # 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 and add a column "color" for the quantity -# used for the color-coding of the bars, here the elevation ("z") +# Convert the grid into a pandas DataFrame, with columns for longitude ("x"), +# latitude ("y") and elevation ("z") grd_df = pygmt.grd2xyz(grid=grid) -grd_df["color"] = grd_df["z"] 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() From 2e9ed08a47ca6348a111eab73065fbc267182b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Thu, 22 Jan 2026 22:18:34 +0100 Subject: [PATCH 19/26] Improve intorduction --- examples/gallery/3d_plots/3d_bar.py | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 20a7d6bf931..2ea34c8fa9b 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -2,24 +2,15 @@ 3-D bar plot ============ -TODO improve introduction +A 3-bar plot can by created from any collection of three-dimensional tabular data. The +data points can lie on a regular grid or be irregular scattered. -A 3-D bar plot of a grid can be created in two steps: (i) convert the grid into a table -via :func:`pygmt.grd2xyz` and (ii) plot 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. - -We can create a 3-D bar plot for any collection of XYZ points, whether they lie on a -regular grid or are irregularly scattered. Therefore, it's clearer to start with a -general description of the 3-D bar plot itself and then mention that, as a special -case, we can convert a grid into XYZ and visualize it with the same routine. - -The program plot3d allows us to plot three-dimensional symbols, including columnar plots. -As a simple demonstration, we will convert a gridded netCDF of bathymetry into an ASCII -xyz table and use the height information to draw a 2-D histogram in a 3-D perspective -view. We also use the height information to set to color of each column via a CPT file. -Our gridded bathymetry file is the 5 arc-minute global relief. Depth ranges from -5000 -meter to sea-level. We produce the Figure by running this script. +A 3-D bar plot based on a grid can be created in two steps: +(i) Convert the grid into table via :func:`pygmt.grd2xyz`. +(ii) Plot 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 later, a fourth column needs to be added containing the values of +the quantity for the color-coding. """ # %% @@ -32,8 +23,8 @@ # 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") +# 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 From d0e0d8e96c7cde7627d03b297b8d019ae311ac7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Sun, 25 Jan 2026 18:52:34 +0100 Subject: [PATCH 20/26] Improve introdcution text --- examples/gallery/3d_plots/3d_bar.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 2ea34c8fa9b..0225c71bbde 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -2,15 +2,19 @@ 3-D bar plot ============ -A 3-bar plot can by created from any collection of three-dimensional tabular data. The -data points can lie on a regular grid or be irregular scattered. +A 3-bar plot can be created from any collection of three-dimensional tabular data. The +data points can lie on a regular grid or be irregular scattered. A special case is +creating such a 3-D bar plot based on a grid. This can be done in two steps: + +(i) 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, e.g., +the elevation. + +(ii) Plotting this table as bars in 3-D using :meth:`pygmt.Figure.plot3d`. -A 3-D bar plot based on a grid can be created in two steps: -(i) Convert the grid into table via :func:`pygmt.grd2xyz`. -(ii) Plot 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 later, a fourth column needs to be added containing the values of -the quantity for the color-coding. +colormap. For the later, a fourth column needs to be added containing the values of the +quantity for the color-coding. """ # %% From a8d3aa5ce5b94057b3b3dc44fcabd90318a0d8b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Sun, 25 Jan 2026 20:19:28 +0100 Subject: [PATCH 21/26] Improve introdcution text --- examples/gallery/3d_plots/3d_bar.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 0225c71bbde..3614bc91ce2 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -6,11 +6,10 @@ data points can lie on a regular grid or be irregular scattered. A special case is creating such a 3-D bar plot based on a grid. This can be done in two steps: -(i) 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, e.g., -the elevation. +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. -(ii) Plotting this table as bars in 3-D using :meth:`pygmt.Figure.plot3d`. +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 later, a fourth column needs to be added containing the values of the From de6528929212c8a99d163a4fb00a6f14ef243957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Sun, 25 Jan 2026 20:28:01 +0100 Subject: [PATCH 22/26] Remove blank line --- examples/gallery/3d_plots/3d_bar.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 3614bc91ce2..02254b32c34 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -8,7 +8,6 @@ 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 From 43c672ec44eb06da5f4d595e35824d70d27e1b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= Date: Sun, 25 Jan 2026 20:36:37 +0100 Subject: [PATCH 23/26] Revert "Remove blank line" This reverts commit de6528929212c8a99d163a4fb00a6f14ef243957. --- examples/gallery/3d_plots/3d_bar.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 02254b32c34..3614bc91ce2 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -8,6 +8,7 @@ 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 From 17d80242972f49c1ad20005764b983d635c21f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Mon, 26 Jan 2026 10:29:46 +0100 Subject: [PATCH 24/26] Fix typos Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- examples/gallery/3d_plots/3d_bar.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 3614bc91ce2..1367503c24c 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -2,8 +2,8 @@ 3-D bar plot ============ -A 3-bar plot can be created from any collection of three-dimensional tabular data. The -data points can lie on a regular grid or be irregular scattered. A special case is +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", @@ -12,7 +12,7 @@ 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 later, a fourth column needs to be added containing the values of the +colormap. For the latter, a fourth column needs to be added containing the values of the quantity for the color-coding. """ From b942514ec6f358ea5ce27110571c9c9a5337d57f Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 26 Jan 2026 19:54:21 +0800 Subject: [PATCH 25/26] Fix examples/gallery/3d_plots/3d_bar.py --- examples/gallery/3d_plots/3d_bar.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 1367503c24c..9b85b1f8b58 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -7,8 +7,7 @@ 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. - + 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 From 20abab442bb7bbf3a45add3495a12884d3933306 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 26 Jan 2026 19:56:10 +0800 Subject: [PATCH 26/26] Fix styling --- examples/gallery/3d_plots/3d_bar.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/gallery/3d_plots/3d_bar.py b/examples/gallery/3d_plots/3d_bar.py index 9b85b1f8b58..70837d40894 100644 --- a/examples/gallery/3d_plots/3d_bar.py +++ b/examples/gallery/3d_plots/3d_bar.py @@ -7,7 +7,8 @@ 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. + 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