Skip to content

Longitude label misplacement with custom lon0 (v2.7.2) #845

Closed

Description

@xiaochen30

Longitude label misplacement with custom lon0 (v2.7.2)

When the prime meridian is shifted via lon0 in cylindrical projection, and the lonlim range wraps across 180°, longitude labels are not placed at the correct tick positions.
Thanks for looking into this.

Reproducible code:
fig, axs = uplt.subplots(proj='cyl', proj_kw={'lon0': 180})
axs.format(lonlim=[70, 220], coast=True, lonlabels=True)

Activity

  1. cvanelteren commented on Oct 18, 2026

    @cvanelteren
    Collaborator
    Image

    looks fine to me, whta am I missing?

  2. xiaochen30 commented on Oct 18, 2026

    @xiaochen30
    Author

    The longitude labels for 120E and 160E are missing. I have tested other longitude ranges, and it works fine in most cases. This seems to be an intermittent label layout issue.

  3. cvanelteren commented on Oct 18, 2026

    @cvanelteren
    Collaborator

    I don't think this is an issue on our end but in cartopy's end.

  4. cvanelteren commented on Oct 18, 2026

    @cvanelteren
    Collaborator

    Actually let me rephrase, not sure if it caused by us or cartpoy, but the issue can be resolved by rotating the labels or making the labels smaller

    Image
    axs.format(
        lonlim=[70, 220],
        coast=True,
        lonlabels=True,
        lonlabelrotation=90,
    )
    
    ``
    
  5. cvanelteren commented on Oct 18, 2026

    @cvanelteren
    Collaborator

    Yeah I checked, we delegate to cartopy.

    You can circumvent this by bypassing this delgation

    with uplt.rc.context({"grid.checkoverlap": False}):
        fig, axs = uplt.subplots(proj="cyl", proj_kw={"lon0": 180})
        axs.format(lonlim=[70, 220], coast=True, lonlabels=True)
        uplt.show()
    
  6. cvanelteren commented on Oct 18, 2026

    @cvanelteren
    Collaborator

    So you can either set this in rc or use local contexts.

  7. xiaochen30 commented on Oct 18, 2026

    @xiaochen30
    Author

    Thanks for the suggestion! I tried your workaround with uplt.rc.context({"grid.checkoverlap": False}). It successfully resolves the intermittent missing longitude labels problem. This workaround works perfectly.

  8. cvanelteren commented on Oct 18, 2026

    @cvanelteren
    Collaborator

    Note that this is not a work around. We delegate to cartopy which makes space for the labels and hiding them when there is an overlap. Setting the rc value to override it will enforce that you use ultraplot formatting. See the docs for more information on setting rc values.

  9. cvanelteren commented on Oct 19, 2026

    @cvanelteren
    Collaborator

    Added an annotation box in the docs for future reference.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions