Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/matplotlib/axes/_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,18 @@ def subplot_class_factory(axes_class=None):
"is deprecated since %(since)s; explicitly pass the default Axes "
"class instead. This will become an error %(removal)s.")
axes_class = Axes

try:
# Avoid creating two different instances of GeoAxesSubplot...
# Only a temporary backcompat fix. This should be removed in
# 3.4
return next(cls for cls in SubplotBase.__subclasses__()
if cls.__bases__ == (SubplotBase, axes_class))
except StopIteration:
# if we have already wrapped this class, declare victory!
if issubclass(axes_class, SubplotBase):
return axes_class

return type("%sSubplot" % axes_class.__name__,
(SubplotBase, axes_class),
{'_axes_class': axes_class})
Expand Down
6 changes: 6 additions & 0 deletions lib/matplotlib/tests/test_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -195,3 +196,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