Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an option to restrict the limits of the gridlines. #1574

Merged
merged 1 commit into from
Jul 14, 2020

Conversation

greglucas
Copy link
Contributor

Rationale

Polar projections often look better without gridlines going all the way to the poles.

Modifying the example from 1568:

import cartopy
import cartopy.crs as ccrs
import numpy as np
import matplotlib.pyplot as plt
import cartopy.feature as cfeature
import matplotlib.ticker as mticker
lats = mticker.FixedLocator(np.arange(-80, 81, 5))
lons = mticker.MultipleLocator(60)
fig = plt.figure(figsize=(6, 3))

ax = fig.add_subplot(121, projection=ccrs.NorthPolarStereo())
ax.set_extent([-180, 180, 70, 90], crs=ccrs.PlateCarree())
ax.gridlines(xlocs=lons, ylocs=lats, ylim=80, xlim=120)
ax.add_feature(cfeature.COASTLINE)

ax = fig.add_subplot(122, projection=ccrs.SouthPolarStereo())
ax.set_extent([-180, 180, -90, -70], crs=ccrs.PlateCarree())
ax.gridlines(xlocs=lons, ylocs=lats, ylim=80, xlim=120)
ax.add_feature(cfeature.COASTLINE)

fig.suptitle(f'Gridlines over polar projections in cartopy v{cartopy.__version__}')

Figure_1

Implications

Fixes #1568

@lukelbd
Copy link
Contributor

lukelbd commented May 25, 2020

Thanks for submitting this! I'm not sure there's even a use case for latitude gridlines that do not extend through all longitudes, so I'm not sure if xlim is even necessary (though that's just from my narrow experience, perhaps others would disagree). It would also be complicated to implement this in cases where central_longitude != 0 -- the gridliner has some existing problems when this is the case (e.g. #1401, #1564).

And maybe something like ymax (similar to latmax in basemap) would make more sense -- to me ylim implies a (ymin, ymax) pair like when you use ax.set_ylim(ylim) on Cartesian axes. If the keyword args xlim and ylim are used they should probably be (minimum, maximum) pairs.

@lukelbd
Copy link
Contributor

lukelbd commented May 25, 2020

Scratch that last comment, just looked at the source code. Looks good to me!

Copy link
Contributor

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@dopplershift dopplershift added this to the 0.19 milestone Jul 14, 2020
@dopplershift dopplershift merged commit f601a53 into SciTools:master Jul 14, 2020
@greglucas greglucas deleted the add_gridlimits branch July 23, 2020 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Longitude gridlines no longer contrained to the latitude gridline range (and vice versa) in cartopy 0.18
3 participants