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

Commitb337f94

Browse files
committed
fix(comment):#29325 (comment)
1 parent0476435 commitb337f94

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

‎lib/matplotlib/axes/_base.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4596,7 +4596,7 @@ def _make_twin_axes(self, *args, **kwargs):
45964596
self._twinned_axes.join(self,twin)
45974597
returntwin
45984598

4599-
deftwinx(self,**kwargs):
4599+
deftwinx(self,axes_class=None,**kwargs):
46004600
"""
46014601
Create a twin Axes sharing the xaxis.
46024602
@@ -4608,6 +4608,11 @@ def twinx(self, **kwargs):
46084608
46094609
Parameters
46104610
----------
4611+
axes_class : subclass type of `~.axes.Axes`, optional
4612+
The `.axes.Axes` subclass that is instantiated. This parameter
4613+
is incompatible with *projection* and *polar*. See
4614+
:ref:`axisartist_users-guide-index` for examples.
4615+
46114616
kwargs : dict
46124617
The keyword arguments passed to ``add_subplot()`` or ``add_axes()``.
46134618
@@ -4621,9 +4626,9 @@ def twinx(self, **kwargs):
46214626
For those who are 'picking' artists while using twinx, pick
46224627
events are only called for the artists in the top-most Axes.
46234628
"""
4624-
ifnot {"projection","polar","axes_class"}.intersection(kwargs):
4625-
kwargs["axes_class"]=type(self)
4626-
ax2=self._make_twin_axes(sharex=self,axes_class=type(self),**kwargs)
4629+
ifaxes_class:
4630+
kwargs["axes_class"]=axes_class
4631+
ax2=self._make_twin_axes(sharex=self,**kwargs)
46274632
ax2.yaxis.tick_right()
46284633
ax2.yaxis.set_label_position('right')
46294634
ax2.yaxis.set_offset_position('right')
@@ -4634,7 +4639,7 @@ def twinx(self, **kwargs):
46344639
ax2.xaxis.units=self.xaxis.units
46354640
returnax2
46364641

4637-
deftwiny(self,**kwargs):
4642+
deftwiny(self,axes_class=None,**kwargs):
46384643
"""
46394644
Create a twin Axes sharing the yaxis.
46404645
@@ -4646,6 +4651,11 @@ def twiny(self, **kwargs):
46464651
46474652
Parameters
46484653
----------
4654+
axes_class : subclass type of `~.axes.Axes`, optional
4655+
The `.axes.Axes` subclass that is instantiated. This parameter
4656+
is incompatible with *projection* and *polar*. See
4657+
:ref:`axisartist_users-guide-index` for examples.
4658+
46494659
kwargs : dict
46504660
The keyword arguments passed to ``add_subplot()`` or ``add_axes()``.
46514661
@@ -4659,9 +4669,9 @@ def twiny(self, **kwargs):
46594669
For those who are 'picking' artists while using twiny, pick
46604670
events are only called for the artists in the top-most Axes.
46614671
"""
4662-
ifnot {"projection","polar","axes_class"}.intersection(kwargs):
4663-
kwargs["axes_class"]=type(self)
4664-
ax2=self._make_twin_axes(sharey=self,axes_class=type(self),**kwargs)
4672+
ifaxes_class:
4673+
kwargs["axes_class"]=axes_class
4674+
ax2=self._make_twin_axes(sharey=self,**kwargs)
46654675
ax2.xaxis.tick_top()
46664676
ax2.xaxis.set_label_position('top')
46674677
ax2.set_autoscaley_on(self.get_autoscaley_on())

‎lib/matplotlib/axes/_base.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import datetime
44
fromcollections.abcimportCallable,Iterable,Iterator,Sequence
55
frommatplotlibimportcbook
66
frommatplotlib.artistimportArtist
7+
frommatplotlib.axesimportAxes
78
frommatplotlib.axisimportXAxis,YAxis,Tick
89
frommatplotlib.backend_basesimportRendererBase,MouseButton,MouseEvent
910
frommatplotlib.cbookimportCallbackRegistry
@@ -28,7 +29,6 @@ import numpy as np
2829
fromnumpy.typingimportArrayLike
2930
fromtypingimportAny,Literal,TypeVar,overload
3031
frommatplotlib.typingimportColorType
31-
fromtyping_extensionsimportSelf
3232

3333
_T=TypeVar("_T",bound=Artist)
3434

@@ -385,8 +385,8 @@ class _AxesBase(martist.Artist):
385385
bbox_extra_artists:Sequence[Artist]|None= ...,
386386
for_layout_only:bool= ...
387387
)->Bbox|None: ...
388-
deftwinx(self,**kwargs)->Self: ...
389-
deftwiny(self,**kwargs)->Self: ...
388+
deftwinx(self,axes_class:Axes|None= ...,**kwargs)->Axes: ...
389+
deftwiny(self,axes_class:Axes|None= ...,**kwargs)->Axes: ...
390390
defget_shared_x_axes(self)->cbook.GrouperView: ...
391391
defget_shared_y_axes(self)->cbook.GrouperView: ...
392392
deflabel_outer(self,remove_inner_ticks:bool= ...)->None: ...

‎lib/matplotlib/tests/test_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7548,7 +7548,7 @@ def test_twinx_subclass(axes_class, kw0, kw1):
75487548
fork,vinkw0.items():
75497549
assertgetattr(classed_ax,k)==v
75507550

7551-
twin=classed_ax.twinx(**kw1)
7551+
twin=classed_ax.twinx(axes_class=axes_class,**kw1)
75527552
asserttype(twin)isaxes_class
75537553
fork,vinkw1.items():
75547554
assertgetattr(twin,k)==v

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp