GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add gallery example for 3-D bar plot by yvonnefroehlich · Pull Request #4315 · GenericMappingTools/pygmt

Conversation

@yvonnefroehlich

@yvonnefroehlich yvonnefroehlich commented Dec 20, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Description of proposed changes

This PR tests to create a 3-D bar plot in PyGMT and addes a gallery example.

Preview: https://pygmt-dev--4315.org.readthedocs.build/en/4315/gallery/3d_plots/3d_bar.html

Guidelines

  • General Guidelines for Pull Request
  • Guidelines for Contributing Documentation
  • Guidelines for Contributing Code

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash command is:

  • /format: automatically format and lint the code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
yvonnefroehlich added 2 commits December 20, 2025 18:47
@yvonnefroehlich
Add code for 3-D bar plot
c3a12c4
@yvonnefroehlich
Remove execution permission
b3ab361
@yvonnefroehlich yvonnefroehlich added the documentation Improvements or additions to documentation label Dec 20, 2025
@yvonnefroehlich yvonnefroehlich self-assigned this Dec 20, 2025
@yvonnefroehlich
yvonnefroehlich marked this pull request as draft December 22, 2025 07:33
yvonnefroehlich and others added 3 commits January 5, 2026 09:04
@yvonnefroehlich
Merge branch 'main' into add-gallery-3dbar
a177004
@yvonnefroehlich
Merge branch 'main' into add-gallery-3dbar
9ba41bb
@yvonnefroehlich
Use Position class
13284df
seisman
seisman reviewed Jan 14, 2026
View reviewed changes
Comment thread examples/gallery/3d_plots/3d_bar.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread examples/gallery/3d_plots/3d_bar.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

yvonnefroehlich and others added 4 commits January 15, 2026 10:43
@yvonnefroehlich
Add introduction text
712aee3
@yvonnefroehlich
Add comments to codes
bfc3ed9
@yvonnefroehlich
Use tuple instead of lists
b9aef30
@yvonnefroehlich
Merge branch 'main' into add-gallery-3dbar
eaa9d5c
@yvonnefroehlich yvonnefroehlich changed the title POC: WIP: Add gallery example for 3-D bar plot WIP: Add gallery example for 3-D bar plot Jan 15, 2026
@yvonnefroehlich yvonnefroehlich changed the title WIP: Add gallery example for 3-D bar plot Add gallery example for 3-D bar plot Jan 15, 2026
@yvonnefroehlich yvonnefroehlich added this to the 0.19.0 milestone Jan 15, 2026
@yvonnefroehlich
yvonnefroehlich marked this pull request as ready for review January 15, 2026 15:55
@yvonnefroehlich yvonnefroehlich added the needs review This PR has higher priority and needs review. label Jan 15, 2026
seisman
seisman reviewed Jan 16, 2026
View reviewed changes
Comment thread examples/gallery/3d_plots/3d_bar.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread examples/gallery/3d_plots/3d_bar.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread examples/gallery/3d_plots/3d_bar.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread examples/gallery/3d_plots/3d_bar.py Outdated
# 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"]

@seisman seisman Jan 16, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the "color" column used anywhere?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@yvonnefroehlich yvonnefroehlich Jan 16, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the "color" column is used for the color-coding.
Alternatively, we could use the incols parameter and use the second column ("z") twice:

# %%
import pygmt
from pygmt.params import Position

# Define a study area with huge 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
grd_df = pygmt.grd2xyz(grid=grid)
zmin = grd_df["z"].min() - 50
zmax = grd_df["z"].max() + 50

# 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,
    # Use the elevation for the color-coding of the bars
    # Zero-based indexing for columns
    incols=[0, 1, 2, 2],  # lon, lat, z for elevation, z for color-coding
)
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()

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@seisman seisman Jan 16, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the point. Need to explain that plot3d requires four columns. The four column is used for color coding. In this example, the fourth column is identical to the z column, but other values are allowed

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread examples/gallery/3d_plots/3d_bar.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

yvonnefroehlich and others added 7 commits January 16, 2026 10:28
@yvonnefroehlich @seisman
Update examples/gallery/3d_plots/3d_bar.py
f8fb0c1
Co-authored-by: Dongdong Tian <[email protected]>
@yvonnefroehlich
Use zmin and zmax
aa0872a
@yvonnefroehlich @seisman
Use grd2xyz without region
68fd801
Co-authored-by: Dongdong Tian <[email protected]>
@yvonnefroehlich
Improve variable name 'grd2tab' to 'grd_df'
9b079e1
@yvonnefroehlich
Improve variable name 'grd2tab' to 'grd_df'
5ac3c3b
@yvonnefroehlich
Try smaller zsize and adjust colorbar offset
074facb
@yvonnefroehlich
Fix line length
55f8c23
seisman
seisman reviewed Jan 16, 2026
View reviewed changes
Comment thread examples/gallery/3d_plots/3d_bar.py Outdated
Comment on lines +5 to +8
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.

@seisman seisman Jan 16, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@yvonnefroehlich yvonnefroehlich Jan 16, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree the introduction texts needs some more work. Thanks for your ideas here 🙂. Will work on this in the next days.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@yvonnefroehlich yvonnefroehlich Jan 25, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made some updates to the introduction text and comments.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@seisman
seisman requested a review from Copilot January 16, 2026 12:42
Copilot started reviewing on behalf of seisman January 16, 2026 12:42
View session
Copilot AI reviewed Jan 16, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new gallery example demonstrating how to create a 3-D bar plot in PyGMT using Earth relief data. The example shows how to convert grid data to a table format and visualize it as color-coded bars in 3D space.

Changes:

  • Adds a new 3-D bar plot example to the gallery
  • Demonstrates grid-to-table conversion using pygmt.grd2xyz
  • Shows color-coded visualization of elevation data using bars in 3D

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread examples/gallery/3d_plots/3d_bar.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

yvonnefroehlich and others added 4 commits January 16, 2026 22:39
@yvonnefroehlich
Improve comment for study region
014474d
@yvonnefroehlich
Update introduction text
2b80bd6
@yvonnefroehlich
Merge branch 'main' into add-gallery-3dbar
d3ba8d4
@yvonnefroehlich
Fix quotation mark
d3ae5b9
@seisman seisman removed the needs review This PR has higher priority and needs review. label Jan 20, 2026
@seisman
seisman marked this pull request as draft January 20, 2026 07:54
yvonnefroehlich and others added 5 commits January 21, 2026 13:11
@yvonnefroehlich
Add intro from GMT example
d769f32
@yvonnefroehlich
Improve comment on fourth column added for color-coding
b0c17b5
@yvonnefroehlich
Merge branch 'main' into add-gallery-3dbar
bc6b5fa
@yvonnefroehlich
Improve intorduction
2e9ed08
@yvonnefroehlich
Merge branch 'main' into add-gallery-3dbar
0e2e414
seisman
seisman reviewed Jan 25, 2026
View reviewed changes
Comment thread examples/gallery/3d_plots/3d_bar.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@yvonnefroehlich
Improve introdcution text
d0e0d8e
@yvonnefroehlich
yvonnefroehlich marked this pull request as ready for review January 25, 2026 17:56
yvonnefroehlich added 3 commits January 25, 2026 20:19
@yvonnefroehlich
Improve introdcution text
a8d3aa5
@yvonnefroehlich
Remove blank line
de65289
@yvonnefroehlich
Revert "Remove blank line"
43c672e
This reverts commit de65289.
seisman
seisman approved these changes Jan 26, 2026
View reviewed changes
@seisman seisman added the final review call This PR requires final review and approval from a second reviewer label Jan 26, 2026
@seisman
seisman requested a review from Copilot January 26, 2026 04:06
Copilot started reviewing on behalf of seisman January 26, 2026 04:07
View session
Copilot AI reviewed Jan 26, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread examples/gallery/3d_plots/3d_bar.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread examples/gallery/3d_plots/3d_bar.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread examples/gallery/3d_plots/3d_bar.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@yvonnefroehlich
Fix typos
17d8024
Co-authored-by: Copilot <[email protected]>
seisman
seisman reviewed Jan 26, 2026
View reviewed changes
Comment thread examples/gallery/3d_plots/3d_bar.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

seisman added 2 commits January 26, 2026 19:54
@seisman
Fix examples/gallery/3d_plots/3d_bar.py
b942514
@seisman
Fix styling
20abab4
@seisman
seisman force-pushed the add-gallery-3dbar branch from 5bb33bc to 20abab4 Compare January 26, 2026 11:57
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Jan 26, 2026
@seisman
seisman merged commit c245644 into main Jan 26, 2026
6 of 8 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@seisman
seisman deleted the add-gallery-3dbar branch January 26, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@seisman seisman seisman approved these changes
Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@yvonnefroehlich yvonnefroehlich

Labels

documentation Improvements or additions to documentation

Projects

None yet

Milestone

0.19.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@yvonnefroehlich @seisman
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.