Skip to content

Conversation

@seisman
Copy link
Member

@seisman seisman commented Dec 2, 2025

This PR improves grdview's -Q option in a more Pythonic way by splitting it into multiple parameters:

  • surftype
  • dpi
  • nan_transparent
  • monochrome
  • mesh_fill

Address #4208 (comment).

Example

import pygmt

grd_relief = pygmt.datasets.load_earth_relief(resolution="15m", region=[-25, -13, 63.2, 66.7])

args = dict(
    region=[-25, -13, 63.2, 66.7], 
    projection="M?", 
    perspective=(-150, 25),
    cmap="SCM/oleron",
    zsize="1.5c",
    plane="+ggray",
    panel=True,
)

fig = pygmt.Figure()
with fig.subplot(nrows=5, ncols=3, subsize=(5, 5), margins=(1, 0.2)):
    for surftype in ("surface", "mesh", "surface+mesh", "image", "waterfall_x", "waterfall_y"):
        fig.grdview(
            grid=grd_relief,
            frame=["xaf", "yaf", f"WSenZ+t{surftype}"],
            surftype=surftype,
            **args,
        )
    for surftype in ("surface", "mesh", "surface+mesh", "image", "waterfall_x", "waterfall_y"):
        fig.grdview(
            grid=grd_relief,
            frame=["xaf", "yaf", f"WSenZ+t{surftype}"],
            surftype=surftype,
            monochrome=True,
            **args,
        )
    for surtype in ("mesh", "waterfall_x", "waterfall_y"):
        fig.grdview(
            grid=grd_relief,
            frame=["xaf", "yaf", f"WSenZ+t{surftype}"],
            surftype=surftype,
            meshfill="red@50",
            **args,
        )
fig.show()
map

),
Alias(dpi, name="dpi"),
Alias(meshfill, name="meshfill"),
Alias(monochrome, name="monochrome", prefix="+m"),
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't +m be a suffix?

Copy link
Member Author

Choose a reason for hiding this comment

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

The full syntax is -Qc|i|m[x|y]|s[m][color][+m]. It's a suffix for the -Q option, but for monochrome, it's a prefix. Since monochrome is a boolean, monochrome would be +m, so here it makes no difference if +m is a prefix or a suffix.

Copy link
Member

Choose a reason for hiding this comment

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

Ah right, got it now.

Copy link
Member

@weiji14 weiji14 Jan 22, 2026

Choose a reason for hiding this comment

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

Just a note that after the suffix feature is implemented in #4259, this +m does need to be a prefix, otherwise a list of values will be returned, xref #4259 (comment).

Comment on lines 194 to 200
"image": "c" if nan_transparent is True else "i",
"waterfallx": "mx",
"waterfally": "my",
}

# surftype was aliased to Q previously.
_old_surftype_syntax = surftype not in _surtype_mapping and surftype is not None
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a unit test to ensure that backwards compatibility is preserved when a user passes surftype="c", but did not set nan_transparent=True (which is added in this PR). The output grdview plot should still have NaN transparency.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in aa9eb73.

@seisman seisman removed this from the 0.18.0 milestone Dec 25, 2025
@seisman seisman added this to the 0.19.0 milestone Dec 25, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jan 10, 2026

Summary of changed images

This is an auto-generated report of images that have changed on the DVC remote

Status Path
added pygmt/tests/baseline/test_grdview_image_dpi.png
added pygmt/tests/baseline/test_grdview_mesh_pen_and_mesh_fill.png
added pygmt/tests/baseline/test_grdview_monochrome.png
added pygmt/tests/baseline/test_grdview_surftype.png
deleted pygmt/tests/baseline/test_grdview_with_cmap_for_image_plot.png
deleted pygmt/tests/baseline/test_grdview_with_cmap_for_perspective_surface_plot.png
deleted pygmt/tests/baseline/test_grdview_with_cmap_for_surface_monochrome_plot.png

Image diff(s)

Details

Added images

  • test_grdview_image_dpi.png

  • test_grdview_mesh_pen_and_mesh_fill.png

  • test_grdview_monochrome.png

  • test_grdview_surftype.png

Modified images

Path Old New

Report last updated at commit 13b00ee

@seisman seisman changed the title Figure.grdview: Pythonic syntax for surftype parameter Figure.grdview: Add parameters surftype/dpi/mesh_fill/nan_transparent/monochrome to control surfure types Jan 11, 2026
@seisman seisman marked this pull request as ready for review January 23, 2026 12:31
@seisman seisman added the needs review This PR has higher priority and needs review. label Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improving an existing feature needs review This PR has higher priority and needs review.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants