Skip to content

Pythonic implemention of the frame="+n" setting #4403

Closed

Description

@seisman

In GMT, -B+n means not plotting any sides of the frame. It's very useful when we want to set the projection and region only without any frames. The GMT source code for parsing the -B option is too complicated to understand, but from what I see, -B+n only works without any other -B settings (e.g., +n setting is ignored if -BWSen+n is used). This can be verified by the following script (colorbar and rose are also used here because the no_frame setting is explicitly used in their source codes):

gmt begin map
gmt basemap -R0/10/0/10 -JX5c -Bafg
gmt colorbar -DJBC+w5c/0.5c+o0c/1c+h -Cjet

gmt basemap -R0/10/0/10 -JX5c -Bafg -B+n -Xw+1
gmt colorbar -DJBC+w5c/0.5c+o0c/1c+h -Cjet -Baf

gmt basemap -R0/10/0/10 -JX5c -Bafg -BWSEN+n -Xw+1
gmt colorbar -DJBC+w5c/0.5c+o0c/1c+h -Cjet -Baf -B+n

gmt basemap -R0/10/0/10 -JX5c -B+n -Xw+1
gmt colorbar -DJBC+w5c/0.5c+o0c/1c+h -Cjet -B+n

gmt rose @azimuth_lengths.txt -: -A5 -JX5c -F -L -Glightblue -R0/1/0/180 -Bxaf+l"Fault length" -Byg30 -S -X-17c -Y7c
gmt rose @azimuth_lengths.txt -: -A5 -JX5c -F -L -Glightblue -R0/1/0/180 -Bxaf+l"Fault length" -Byg30 -B+n -S -Xw+1
gmt rose @azimuth_lengths.txt -: -A5 -JX5c -F -L -Glightblue -R0/1/0/180 -B+n -S -Xw+1

gmt end show

The output is:
Image

Then, what's the Pythonic implementation for -B+n? In PR #4016, we're working on the Frame/Axis class, which wraps the complicated -B option. Of course, we can implement something like Frame(noframe=True), but it looks tedious and is not intuitive.

I think there are a few different implementations for -B+n:

  1. Add a standalone parameter like noframe=True (or no_frame=True). If I understand it correctly, GMT.jl also implements it similarly (see https://www.generic-mapping-tools.org/GMTjl_doc/documentation/common_opts/common_opts.html). Its usage is frame=(noframe=True,).
  2. Map frame="none" to -B+n. It seems GMT.jl also supports it (frame=:none).
  3. Let frame=False mean no frame. Previously, frame=False meant -B is not set, so it breaks backward compatibility.

I feel option 2 is the simplest to implement and is also intuitive. What do you think? @GenericMappingTools/pygmt-maintainers

Activity

  1. added
    discussions
    on Feb 9, 2026
  2. yvonnefroehlich commented on Feb 9, 2026

    @yvonnefroehlich
    Member

    Oh yes, I agree this +n option is great and very useful and often better than doing something like +gwhite@100, as the figure is also cut. I believe this is something that is relatively new in GMT; I was missing this at the beginning of my PhD time.

    • option 1: frame=(noframe=True) has a bit of using double negatives.
    • option 2: Sofar, I think, I prefer this option.
    • option 3: I think frame="none" is clearer as frame=False, as frame is not a binary parameter (in contrast to, e.g., no_clip)
  3. added this to the 0.19.0 milestone on Feb 10, 2026
  4. added
    enhancement
    and removed
    discussions
    on Feb 10, 2026
  5. seisman commented on Feb 10, 2026

    @seisman
    MemberAuthor

    In PR #4404, I've implemented frame="none" to mean no frame. However, it should be noted that the current behavior of frame=True, frame=False, and frame=None varies inconsistently across GMT modules.

    The behavior after PR #4404

    Case basemap colorbar / rose Other modules (e.g., coast)
    frame=False / frame=None (no -B) Invalid* Annotate from CPT intervals No frame
    frame=True (-B) Automatic frame Automatic frame Automatic frame
    frame="none" (-B+n) No frame No frame No frame

    *-B is required except in subplot mode, especially after -D/-L/-T are deprecated

    Proposal 1

    If we map frame=False to -B+n (no frame) and make frame=None the default:**

    Case basemap colorbar Other modules
    frame=None (no -B) Invalid* Annotate from CPT No frame
    frame=True (-B) Automatic frame Automatic frame Automatic frame
    frame=False (-B+n) No frame No frame No frame

    The new behavior seems more consistent and easier to document:

    Value Meaning
    frame=None Module-dependent default behavior
    frame=True Enable automatic frame settings
    frame=False Disable frame entirely

    Is it a breaking change? Technically yes, but with limited impact:

    Module Old frame=False New frame=False Risk Level
    basemap Error (no -B) No frame High
    colorbar / rose CPT-based annotations No annotations Moderate—silent output change
    coast, plot, etc. No frame No frame None: identical output

    It's rare that normal users would pass frame=False to any plotting methods, so the impact should be limited, but I can see that passing frame=False may happen when users write high-level functions that wrap multiple PyGMT methods. So, the impact is still high, especially that, in subplot mode, frame=False means letting subplot decide the frame settting, but now frame=False means no frame, which is quite a breaking change.

    Proposal 2

    What about making frame=None the default and implement frame="auto" and frame="none"?

    Case basemap colorbar Other modules
    frame=None (no -B) Invalid* Annotate from CPT No frame
    frame="auto" (-B) Automatic frame Automatic frame Automatic frame
    frame="none" (-B+n) No frame No frame No frame

    frame=True/frame=False are still supported (so no breaking change), but only document frame="auto" and frame="none" (maybe also mention frame=True since it's heavily used).

    In other words, PR #4404 is ready for review, and if we decide to accept proposal 2, then we need a separate PR implementing frame="auto".

  6. added
    discussions
    on Feb 10, 2026
  7. removed
    discussions
    on Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions