3
3
The base axes class used for all ProPlot figures.
4
4
"""
5
5
import numpy as np
6
- from numbers import Integral , Number
6
+ import copy
7
7
import matplotlib .axes as maxes
8
8
import matplotlib .ticker as mticker
9
9
import matplotlib .patches as mpatches
10
10
import matplotlib .transforms as mtransforms
11
11
import matplotlib .collections as mcollections
12
+ import matplotlib .projections as mprojections
13
+ from numbers import Integral , Number
12
14
from .plot import (
13
15
_get_transform ,
14
16
_bar_wrapper , _barh_wrapper , _boxplot_wrapper ,
21
23
colorbar_wrapper , legend_wrapper ,
22
24
)
23
25
from .. import gridspec as pgridspec
26
+ from .. import constructor
24
27
from ..config import rc
25
28
from ..utils import units , edges
26
29
from ..internals import ic # noqa: F401
101
104
`~matplotlib.axes.Axes.transAxes`,
102
105
or `~matplotlib.figure.Figure.transFigure` transforms. Default is
103
106
``'axes'``, i.e. `bounds` is in axes-relative coordinates.
107
+ proj, projection : str, `cartopy.crs.Projection`, or `~mpl_toolkits.basemap.Basemap`
108
+ The map projection specification(s). If not provided, the inset axes
109
+ projection is identical to the current axes projection. If ``'cartesian'``,
110
+ a `~proplot.axes.CartesianAxes` inset is created. If ``'polar'``, a
111
+ `~proplot.axes.PolarAxes` inset is created. Otherwise, the argument is
112
+ interpreted by `~proplot.constructor.Proj`, and the result is used
113
+ to make a `~proplot.axes.GeoAxes` (in this case the argument can be
114
+ a `cartopy.crs.Projection` instance, a `~mpl_toolkits.basemap.Basemap`
115
+ instance, or a projection name listed in :ref:`this table <proj_table>`).
116
+ proj_kw, projection_kw : dict-like, optional
117
+ Keyword arguments passed to `~mpl_toolkits.basemap.Basemap` or
118
+ cartopy `~cartopy.crs.Projection` classes on instantiation.
119
+ basemap : bool or dict-like, optional
120
+ Whether to use `~mpl_toolkits.basemap.Basemap` or
121
+ `~cartopy.crs.Projection` for map projections. Default is ``False``.
104
122
zorder : float, optional
105
123
The `zorder <https://matplotlib.org/3.1.1/gallery/misc/zorder_demo.html>`__
106
124
of the axes, should be greater than the zorder of
@@ -1435,8 +1453,9 @@ def inset(self, *args, **kwargs):
1435
1453
1436
1454
@docstring .add_snippets
1437
1455
def inset_axes (
1438
- self , bounds , * , transform = None , zorder = 4 ,
1439
- zoom = True , zoom_kw = None ,
1456
+ self , bounds , transform = None , zorder = 4 ,
1457
+ zoom = None , zoom_kw = None ,
1458
+ proj = None , proj_kw = None , projection = None , projection_kw = None , basemap = None ,
1440
1459
** kwargs
1441
1460
):
1442
1461
"""
@@ -1448,18 +1467,43 @@ def inset_axes(
1448
1467
else :
1449
1468
transform = _get_transform (self , transform )
1450
1469
label = kwargs .pop ('label' , 'inset_axes' )
1470
+ proj = _not_none (proj = proj , projection = projection )
1471
+ proj_kw = _not_none (proj_kw = proj_kw , projection_kw = projection_kw , default = {})
1472
+
1473
+ # Inherit from current axes
1474
+ if proj is None :
1475
+ proj = self .name
1476
+ if basemap is not None :
1477
+ proj_kw ['basemap' ] = basemap
1478
+ if proj_kw :
1479
+ warnings ._warn_proplot (
1480
+ 'Inheriting projection from the main axes. '
1481
+ f'Ignoring proj_kw keyword args: { proj_kw } '
1482
+ )
1483
+ if proj in ('cartopy' , 'basemap' ):
1484
+ map_projection = copy .copy (self .projection )
1485
+ kwargs .setdefault ('map_projection' , map_projection )
1486
+
1487
+ # Create new projection
1488
+ elif proj == 'cartesian' :
1489
+ pass
1490
+ elif proj == 'polar' :
1491
+ proj = 'polar2' # custom proplot name
1492
+ else :
1493
+ proj_kw .setdefault ('basemap' , basemap )
1494
+ map_projection = constructor .Proj (proj , ** proj_kw )
1495
+ kwargs .setdefault ('map_projection' , map_projection )
1496
+ proj = 'basemap' if proj_kw ['basemap' ] else 'cartopy'
1451
1497
1452
1498
# This puts the rectangle into figure-relative coordinates.
1453
- from .cartesian import CartesianAxes
1454
1499
locator = self ._make_inset_locator (bounds , transform )
1500
+ cls = mprojections .get_projection_class (proj )
1455
1501
bb = locator (None , None )
1456
- ax = CartesianAxes (
1457
- self .figure , bb .bounds ,
1458
- zorder = zorder , label = label , ** kwargs
1459
- )
1502
+ ax = cls (self .figure , bb .bounds , zorder = zorder , label = label , ** kwargs )
1460
1503
1461
1504
# The following locator lets the axes move if we used data coordinates,
1462
1505
# is called by ax.apply_aspect()
1506
+ zoom = _not_none (zoom , self .name == ax .name ) # only zoom when same projection
1463
1507
ax .set_axes_locator (locator )
1464
1508
self .add_child_axes (ax )
1465
1509
ax ._inset_zoom = zoom
0 commit comments