Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9caa261

Browse files
authored
Merge pull request#22608 from rcomer/inset-add_axes
Axes.inset_axes: enable Axes subclass creation
2 parents2f7e53d +80e672e commit9caa261

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Axes.inset_axes Flexibility
2+
---------------------------
3+
4+
`matplotlib.axes.Axes.inset_axes` now accepts the *projection*, *polar* and
5+
*axes_class* keyword arguments, so that subclasses of `matplotlib.axes.Axes` may
6+
be returned.

‎lib/matplotlib/axes/_axes.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,27 @@ def inset_axes(self, bounds, *, transform=None, zorder=5, **kwargs):
325325
Defaults to `ax.transAxes`, i.e. the units of *rect* are in
326326
Axes-relative coordinates.
327327
328+
projection : {None, 'aitoff', 'hammer', 'lambert', 'mollweide',\
329+
'polar', 'rectilinear', str}, optional
330+
The projection type of the inset `~.axes.Axes`. *str* is the name
331+
of a custom projection, see `~matplotlib.projections`. The default
332+
None results in a 'rectilinear' projection.
333+
334+
polar : bool, default: False
335+
If True, equivalent to projection='polar'.
336+
337+
axes_class : subclass type of `~.axes.Axes`, optional
338+
The `.axes.Axes` subclass that is instantiated. This parameter
339+
is incompatible with *projection* and *polar*. See
340+
:ref:`axisartist_users-guide-index` for examples.
341+
328342
zorder : number
329343
Defaults to 5 (same as `.Axes.legend`). Adjust higher or lower
330344
to change whether it is above or below data plotted on the
331345
parent Axes.
332346
333347
**kwargs
334-
Other keyword arguments are passed on to thechild `.Axes`.
348+
Other keyword arguments are passed on to theinsetAxes class.
335349
336350
Returns
337351
-------
@@ -357,7 +371,10 @@ def inset_axes(self, bounds, *, transform=None, zorder=5, **kwargs):
357371
# This puts the rectangle into figure-relative coordinates.
358372
inset_locator=_TransformedBoundsLocator(bounds,transform)
359373
bounds=inset_locator(self,None).bounds
360-
inset_ax=Axes(self.figure,bounds,zorder=zorder,**kwargs)
374+
projection_class,pkw=self.figure._process_projection_requirements(
375+
bounds,**kwargs)
376+
inset_ax=projection_class(self.figure,bounds,zorder=zorder,**pkw)
377+
361378
# this locator lets the axes move if in data coordinates.
362379
# it gets called in `ax.apply_aspect() (of all places)
363380
inset_ax.set_axes_locator(inset_locator)

‎lib/matplotlib/tests/test_axes.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@
2626
importmatplotlib.markersasmmarkers
2727
importmatplotlib.patchesasmpatches
2828
importmatplotlib.pathasmpath
29+
frommatplotlib.projections.geoimportHammerAxes
30+
frommatplotlib.projections.polarimportPolarAxes
2931
importmatplotlib.pyplotasplt
3032
importmatplotlib.textasmtext
3133
importmatplotlib.tickerasmticker
3234
importmatplotlib.transformsasmtransforms
35+
importmpl_toolkits.axisartistasAA
3336
fromnumpy.testingimport (
3437
assert_allclose,assert_array_equal,assert_array_almost_equal)
3538
frommatplotlib.testing.decoratorsimport (
@@ -2545,8 +2548,6 @@ def get_next_color():
25452548

25462549
deftest_as_mpl_axes_api():
25472550
# tests the _as_mpl_axes api
2548-
frommatplotlib.projections.polarimportPolarAxes
2549-
25502551
classPolar:
25512552
def__init__(self):
25522553
self.theta_offset=0
@@ -6625,6 +6626,31 @@ def test_zoom_inset():
66256626
axin1.get_position().get_points(),xx,rtol=1e-4)
66266627

66276628

6629+
@image_comparison(['inset_polar.png'],remove_text=True,style='mpl20')
6630+
deftest_inset_polar():
6631+
_,ax=plt.subplots()
6632+
axins=ax.inset_axes([0.5,0.1,0.45,0.45],polar=True)
6633+
assertisinstance(axins,PolarAxes)
6634+
6635+
r=np.arange(0,2,0.01)
6636+
theta=2*np.pi*r
6637+
6638+
ax.plot(theta,r)
6639+
axins.plot(theta,r)
6640+
6641+
6642+
deftest_inset_projection():
6643+
_,ax=plt.subplots()
6644+
axins=ax.inset_axes([0.2,0.2,0.3,0.3],projection="hammer")
6645+
assertisinstance(axins,HammerAxes)
6646+
6647+
6648+
deftest_inset_subclass():
6649+
_,ax=plt.subplots()
6650+
axins=ax.inset_axes([0.2,0.2,0.3,0.3],axes_class=AA.Axes)
6651+
assertisinstance(axins,AA.Axes)
6652+
6653+
66286654
@pytest.mark.parametrize('x_inverted', [False,True])
66296655
@pytest.mark.parametrize('y_inverted', [False,True])
66306656
deftest_indicate_inset_inverted(x_inverted,y_inverted):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp