Skip to content

Commit c9ca0bd

Browse files
committed
Add 'basemap' and 'cartopy.circular' rc settings
1 parent 89bd9ec commit c9ca0bd

File tree

5 files changed

+36
-22
lines changed

5 files changed

+36
-22
lines changed

docs/projections.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,16 @@
150150
#
151151
# .. note::
152152
#
153-
# * ProPlot ensures that polar cartopy projections like
154-
# `~cartopy.crs.NorthPolarStereo` have circular boundaries (see `this example\
153+
# * By default, ProPlot gives circular boundaries to polar cartopy projections like
154+
# `~cartopy.crs.NorthPolarStereo` (see `this example\
155155
# <https://scitools.org.uk/cartopy/docs/latest/gallery/lines_and_polygons/always_circular_stereo.html>`__
156-
# from the cartopy website).
157-
# * By default, non-polar cartopy projections are forced to have global extent
158-
# with `~cartopy.mpl.geoaxes.GeoAxes.set_global` and polar cartopy projections
159-
# are bounded at the equator. This stands in contrast to the default cartopy
160-
# behavior, where map boundaries are determined automatically based on the
161-
# coordinates of the plotted content. To revert to cartopy's default behavior,
162-
# set :rcraw:`cartopy.autoextent` to ``True`` or pass ``autoextent=True``
163-
# to `~proplot.axes.CartopyAxes`.
156+
# from the cartopy website). This is consistent with basemap's default behavior.
157+
# To disable this feature, set :rcraw:`cartopy.circular` to ``False``.
158+
# * By default, ProPlot uses `~cartopy.mpl.geoaxes.GeoAxes.set_global` to give
159+
# non-polar cartopy projections global extent and bounds polar cartopy projections
160+
# at the equator. This is a deviation from cartopy, which determines map boundaries
161+
# automatically based on the coordinates of the plotted content. To revert to
162+
# cartopy's default behavior, set :rcraw:`cartopy.autoextent` to ``True``.
164163
# * To make things more consistent between cartopy and basemap, the
165164
# `~proplot.constructor.Proj` constructor function lets you supply native
166165
# `PROJ <https://proj.org>`__ keyword names for the cartopy

proplot/axes/geo.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
__all__ = ['GeoAxes', 'BasemapAxes', 'CartopyAxes']
4949

5050

51-
def _circle_boundary(N=100):
51+
def _circular_boundary(N=100):
5252
"""
5353
Return a circle `~matplotlib.path.Path` used as the outline for polar
5454
stereographic, azimuthal equidistant, Lambert conformal, and gnomonic
@@ -718,13 +718,18 @@ class CartopyAxes(GeoAxes, GeoAxesBase):
718718
)
719719
_proj_polar = _proj_north + _proj_south
720720

721-
def __init__(self, *args, autoextent=None, map_projection=None, **kwargs):
721+
def __init__(
722+
self, *args, autoextent=None, circular=None, map_projection=None, **kwargs
723+
):
722724
"""
723725
Parameters
724726
----------
725727
autoextent : bool, optional
726728
Whether to automatically adjust map bounds based on plotted content
727729
or enforce *global* map extent. Default is :rc:`cartopy.autoextent`.
730+
circular : bool, optional
731+
Whether to bound polar projections with circles rather than squares.
732+
Default is :rc:`cartopy.circular`.
728733
map_projection : `~cartopy.crs.Projection`
729734
The `~cartopy.crs.Projection` instance.
730735
@@ -770,9 +775,10 @@ def __init__(self, *args, autoextent=None, map_projection=None, **kwargs):
770775
# can do their things. This also updates _LatAxis and _LonAxis.
771776
# NOTE: Use set_global rather than _update_extent() manually in case projection
772777
# extent cannot be global.
773-
if polar and hasattr(self, 'set_boundary'):
774-
self.set_boundary(_circle_boundary(), transform=self.transAxes)
775778
auto = _not_none(autoextent, rc['cartopy.autoextent'])
779+
circular = _not_none(circular, rc['cartopy.circular'])
780+
if polar and circular and hasattr(self, 'set_boundary'):
781+
self.set_boundary(_circular_boundary(), transform=self.transAxes)
776782
if auto:
777783
self._set_view_intervals(self._get_global_extent())
778784
elif polar:

proplot/constructor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ def Proj(name, basemap=None, **kwargs):
12611261
12621262
basemap : bool, optional
12631263
Whether to use the basemap package as opposed to the cartopy package.
1264-
Default is ``False``.
1264+
Default is :rc:`basemap`.
12651265
lonlim : 2-tuple of float, optional
12661266
Alternative way to specify `llcrnrlon` and `urcrnrlon` for basemap
12671267
projections.
@@ -1351,7 +1351,7 @@ def Proj(name, basemap=None, **kwargs):
13511351
)
13521352

13531353
# Basemap
1354-
elif basemap:
1354+
elif basemap or basemap is None and rc['basemap']:
13551355
# NOTE: Known issue that basemap sometimes produces backwards maps:
13561356
# https://stackoverflow.com/q/56299971/4970632
13571357
# NOTE: We set rsphere to fix non-conda installed basemap issue:

proplot/internals/rcsetup.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,12 @@
363363
'Alias for :rcraw:`axes.formatter.offset_threshold`.'
364364
),
365365

366+
# Special basemap settings
367+
'basemap': (
368+
False,
369+
'Boolean, toggles whether basemap is the default backend.'
370+
),
371+
366372
# Country borders
367373
'borders': (
368374
False,
@@ -398,9 +404,13 @@
398404
# Special cartopy settings
399405
'cartopy.autoextent': (
400406
False,
401-
'If ``False`` (the default), the projection extent is no longer automatically '
402-
'adjusted based on plotted content. See the :ref:`user guide <ug_geo>` for '
403-
'details.'
407+
'If ``False`` (the default), cartopy projection extents are global by '
408+
'default and no longer automatically adjusted based on plotted content.'
409+
),
410+
'cartopy.circular': (
411+
True,
412+
"If ``True`` (the default), polar cartopy projections like ``'npstere'`` and "
413+
"``'spstere'`` are bounded with circles rather than squares."
404414
),
405415

406416
# Coastlines

proplot/ui.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def subplots(
309309
basemap : bool, list of bool, or dict of bool, optional
310310
Passed to `~proplot.constructor.Proj`, determines whether projection
311311
string names like ``'pcarree'`` are used to create `~proplot.axes.BasemapAxes`
312-
or `~proplot.axes.CartopyAxes`. Default is ``False``. If boolean, applies
312+
or `~proplot.axes.CartopyAxes`. Default is :rc:`basemap`. If boolean, applies
313313
to all subplots. If list or dict, applies to specific subplots, as with `proj`.
314314
journal : str, optional
315315
String name corresponding to an academic journal standard that is used
@@ -562,8 +562,7 @@ def subplots(
562562
subplotspec = gridspec[y0:y1 + 1, x0:x1 + 1]
563563
with fig._context_authorize_add_subplot():
564564
axs[idx] = fig.add_subplot(
565-
subplotspec, number=num, main=True,
566-
**axes_kw[num]
565+
subplotspec, number=num, main=True, **axes_kw[num]
567566
)
568567

569568
# Shared axes setup

0 commit comments

Comments
 (0)