diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index 71da8d122409..b38dd583ca6e 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -2211,6 +2211,10 @@ def _make_class_factory(mixin_class, fmt, attr_name=None): @functools.lru_cache(None) def class_factory(axes_class): + # if we have already wrapped this class, declare victory! + if issubclass(axes_class, mixin_class): + return axes_class + # The parameter is named "axes_class" for backcompat but is really just # a base class; no axes semantics are used. base_class = axes_class diff --git a/lib/matplotlib/tests/test_subplots.py b/lib/matplotlib/tests/test_subplots.py index 71e3d146bb80..03efd18a1e6e 100644 --- a/lib/matplotlib/tests/test_subplots.py +++ b/lib/matplotlib/tests/test_subplots.py @@ -5,6 +5,7 @@ import matplotlib.pyplot as plt from matplotlib.testing.decorators import image_comparison +import matplotlib.axes as maxes def check_shared(axs, x_shared, y_shared): @@ -219,3 +220,8 @@ def test_dont_mutate_kwargs(): gridspec_kw=gridspec_kw) assert subplot_kw == {'sharex': 'all'} assert gridspec_kw == {'width_ratios': [1, 2]} + + +def test_subplot_factory_reapplication(): + assert maxes.subplot_class_factory(maxes.Axes) is maxes.Subplot + assert maxes.subplot_class_factory(maxes.Subplot) is maxes.Subplot