8000 Apply suggestions from code review · matplotlib/matplotlib@ecb384e · GitHub
[go: up one dir, main page]

Skip to content

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

Appearance settings

Commit ecb384e

Browse files
cmp0xfftimhoffm
andcommitted
1 parent e9ce871 commit ecb384e

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4613,6 +4613,8 @@ def twinx(self, axes_class=None, **kwargs):
46134613
is incompatible with *projection* and *polar*. See
46144614
:ref:`axisartist_users-guide-index` for examples.
46154615
4616+
By default, `~.axes.Axes` is used.
4617+
46164618
kwargs : dict
46174619
The keyword arguments passed to ``add_subplot()`` or ``add_axes()``.
46184620
@@ -4656,6 +4658,8 @@ def twiny(self, axes_class=None, **kwargs):
46564658
is incompatible with *projection* and *polar*. See
46574659
:ref:`axisartist_users-guide-index` for examples.
46584660
4661+
By default, `~.axes.Axes` is used.
4662+
46594663
kwargs : dict
46604664
The keyword arguments passed to ``add_subplot()`` or ``add_axes()``.
46614665

lib/matplotlib/tests/test_axes.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7538,21 +7538,27 @@ def __init__(self, *args, foo, **kwargs):
75387538
self.foo = foo
75397539

75407540

7541-
@pytest.mark.parametrize("twinning", ["twinx", "twiny"])
7542-
@pytest.mark.parametrize(("axes_class", "kw0", "kw1"), [
7543-
(Axes, {}, {}),
7544-
(SubclassAxes, {"foo": 0}, {"foo": 1}),
7545-
])
7546-
def test_twinning_subclass(twinning, axes_class, kw0, kw1):
7547-
fig = plt.figure()
7548-
classed_ax = fig.add_subplot(axes_class=axes_class, **kw0)
7549-
for k, v in kw0.items():
7550-
assert getattr(classed_ax, k) == v
7551-
7552-
twin = getattr(classed_ax, twinning)(axes_class=axes_class, **kw1)
7553-
assert type(twin) is axes_class
7554-
for k, v in kw1.items():
7555-
assert getattr(twin, k) == v
7541+
def test_twinning_with_axes_class():
7542+
"""Check that twinx/y(axes_class=...) gives the appropriate class."""
7543+
_, ax = plt.subplots()
7544+
twinx = ax.twinx(axes_class=SubclassAxes, foo=1)
7545+
assert isinstance(twinx, SubclassAxes)
7546+
assert twinx.foo == 1
7547+
twiny = ax.twiny(axes_class=SubclassAxes, foo=2)
7548+
assert isinstance(twiny, SubclassAxes)
7549+
assert twiny.foo == 2
7550+
7551+
7552+
def test_twinning_default_axes_class():
7553+
"""
7554+
Check that the default class for twinx/y() is Axes,
7555+
even if the original is an Axes subclass.
7556+
"""
7557+
_, ax = plt.subplots(subplot_kw=dict(axes_class=SubclassAxes, foo=1))
7558+
twinx = ax.twinx()
7559+
assert type(twinx) is Axes
7560+
twiny = ax.twiny()
7561+
assert type(twiny) is Axes
75567562

75577563

75587564
def test_zero_linewidth():

0 commit comments

Comments
 (0)
0