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

Appearance settings

Commit b4e44c2

Browse filesBrowse files
authored
Merge pull request #12135 from meeseeksmachine/auto-backport-of-pr-12131-on-v3.0.x
Backport PR #12131 on branch v3.0.x (Fixes currently release version of cartopy)
2 parents 3831542 + 9c82c34 commit b4e44c2
Copy full SHA for b4e44c2

File tree

Expand file treeCollapse file tree

2 files changed

+40
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+40
-3
lines changed

‎lib/matplotlib/axes/_subplots.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_subplots.py
+22-3Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,18 @@ def _make_twin_axes(self, *kl, **kwargs):
188188
return ax2
189189

190190

191+
# this here to support cartopy which was using a private part of the
192+
# API to register their Axes subclasses.
193+
194+
# In 3.1 this should be changed to a dict subclass that warns on use
195+
# In 3.3 to a dict subclass that raises a useful exception on use
196+
# In 3.4 should be removed
197+
198+
# The slow timeline is to give cartopy enough time to get several
199+
# release out before we break them.
200+
_subplot_classes = {}
201+
202+
191203
@functools.lru_cache(None)
192204
def subplot_class_factory(axes_class=None):
193205
"""
@@ -199,9 +211,16 @@ def subplot_class_factory(axes_class=None):
199211
"""
200212
if axes_class is None:
201213
axes_class = Axes
202-
return type("%sSubplot" % axes_class.__name__,
203-
(SubplotBase, axes_class),
204-
{'_axes_class': axes_class})
214+
try:
215+
# Avoid creating two different instances of GeoAxesSubplot...
216+
# Only a temporary backcompat fix. This should be removed in
217+
# 3.4
218+
return next(cls for cls in SubplotBase.__subclasses__()
219+
if cls.__bases__ == (SubplotBase, axes_class))
220+
except StopIteration:
221+
return type("%sSubplot" % axes_class.__name__,
222+
(SubplotBase, axes_class),
223+
{'_axes_class': axes_class})
205224

206225

207226
# This is provided for backward compatibility

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5789,3 +5789,21 @@ def test_spines_properbbox_after_zoom():
57895789
None, False, False)
57905790
bb2 = ax.spines['bottom'].get_window_extent(fig.canvas.get_renderer())
57915791
np.testing.assert_allclose(bb.get_points(), bb2.get_points(), rtol=1e-6)
5792+
5793+
5794+
def test_cartopy_backcompat():
5795+
import matplotlib
5796+
import matplotlib.axes
5797+
import matplotlib.axes._subplots
5798+
5799+
class Dummy(matplotlib.axes.Axes):
5800+
...
5801+
5802+
class DummySubplot(matplotlib.axes.SubplotBase, Dummy):
5803+
_axes_class = Dummy
5804+
5805+
matplotlib.axes._subplots._subplot_classes[Dummy] = DummySubplot
5806+
5807+
FactoryDummySubplot = matplotlib.axes.subplot_class_factory(Dummy)
5808+
5809+
assert DummySubplot is FactoryDummySubplot

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.