Skip to content

Add capability for non-inline grid labels to appear inside map #1642

@karlwx

Description

@karlwx

I want to be able to adjust the position of the grid tick labels to be inside the map boundary. Setting the gridliner xpadding works to move the labels away from the map, but setting the xpadding to a negative number results in hidden labels. I found that that non-inline labels that overlap the map boundary are hidden by default, so I experimented with setting the visibility of all labels to true. However, that resulted in the labels appearing at a 45-degree angle.

I'm essentially trying to do something like this. Note: I am not looking to use the inline labels option, since (at least to my knowledge) there isn't a way to fix their positions to a particular x or y offset from the map boundaries. Changing the xpadding doesn't have any effect with the inline labels. Maybe this should be an option instead?

Example code:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs

plt.figure(figsize=(12,9))
ax = plt.axes(projection=ccrs.Miller())
ax.set_extent([-130,-65,20,55], crs=ccrs.PlateCarree())
ax.coastlines(resolution='50m')
gl = ax.gridlines(draw_labels=True, color='gray', linestyle='--')
gl.top_labels, gl.right_labels = False, False
gl.xlabel_style, gl.ylabel_style = {'weight': 'bold'}, {'weight': 'bold'}
#gl.xpadding = -10     # Ideally, this would move labels inside the map, but results in hidden labels

No xpadding:
Screenshot from 2020-08-25 10-51-30

xpadding set to -10 and visibility hard-coded to True results in rotated labels:
Screenshot from 2020-08-25 10-50-55

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions