Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e1206cc

Browse files
committed
Backport PR #20403: FIX: if we have already subclassed mixin class just return
Merge pull request #20403 from tacaswell/noop_subplot_class_factory FIX: if we have already subclassed mixin class just return Conflicts: lib/matplotlib/cbook/__init__.py - logic is in axes/_subplots.py on this branch
1 parent bc6cb1b commit e1206cc

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/matplotlib/axes/_subplots.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,18 @@ def subplot_class_factory(axes_class=None):
175175
"is deprecated since %(since)s; explicitly pass the default Axes "
176176
"class instead. This will become an error %(removal)s.")
177177
axes_class = Axes
178+
178179
try:
179180
# Avoid creating two different instances of GeoAxesSubplot...
180181
# Only a temporary backcompat fix. This should be removed in
181182
# 3.4
182183
return next(cls for cls in SubplotBase.__subclasses__()
183184
if cls.__bases__ == (SubplotBase, axes_class))
184185
except StopIteration:
186+
# if we have already wrapped this class, declare victory!
187+
if issubclass(axes_class, SubplotBase):
188+
return axes_class
189+
185190
return type("%sSubplot" % axes_class.__name__,
186191
(SubplotBase, axes_class),
187192
{'_axes_class': axes_class})

lib/matplotlib/tests/test_subplots.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import matplotlib.pyplot as plt
77
from matplotlib.testing.decorators import image_comparison
8+
import matplotlib.axes as maxes
89

910

1011
def check_shared(axs, x_shared, y_shared):
@@ -195,3 +196,8 @@ def test_dont_mutate_kwargs():
195196
gridspec_kw=gridspec_kw)
196197
assert subplot_kw == {'sharex': 'all'}
197198
assert gridspec_kw == {'width_ratios': [1, 2]}
199+
200+
201+
def test_subplot_factory_reapplication():
202+
assert maxes.subplot_class_factory(maxes.Axes) is maxes.Subplot
203+
assert maxes.subplot_class_factory(maxes.Subplot) is maxes.Subplot

0 commit comments

Comments
 (0)