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

Fixes currently release version of cartopy #12131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2018
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
25 changes: 22 additions & 3 deletions 25 lib/matplotlib/axes/_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ def _make_twin_axes(self, *kl, **kwargs):
return ax2


# this here to support cartopy which was using a private part of the
# API to register their Axes subclasses.

# In 3.1 this should be changed to a dict subclass that warns on use
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not start warning on use in this version? Warning is basically free after all and it gives more notice.

Copy link
Member Author

@tacaswell tacaswell Sep 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there is not a released version of cartopy with the fix on their side yet. I don't want to warn at their users and give them no way to fix it.

[corrected typo]

# In 3.3 to a dict subclass that raises a useful exception on use
# In 3.4 should be removed

# The slow timeline is to give cartopy enough time to get several
# release out before we break them.
_subplot_classes = {}


@functools.lru_cache(None)
def subplot_class_factory(axes_class=None):
"""
Expand All @@ -198,9 +210,16 @@ def subplot_class_factory(axes_class=None):
"""
if axes_class is None:
axes_class = Axes
return type("%sSubplot" % axes_class.__name__,
(SubplotBase, axes_class),
{'_axes_class': axes_class})
try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be clearer if you use a for / else loop.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm indifferent either way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, for/else would be clearer, but since this is a temporary workaround I don‘t care too much.

# 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:
return type("%sSubplot" % axes_class.__name__,
(SubplotBase, axes_class),
{'_axes_class': axes_class})


# This is provided for backward compatibility
Expand Down
18 changes: 18 additions & 0 deletions 18 lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5789,3 +5789,21 @@ def test_spines_properbbox_after_zoom():
None, False, False)
bb2 = ax.spines['bottom'].get_window_extent(fig.canvas.get_renderer())
np.testing.assert_allclose(bb.get_points(), bb2.get_points(), rtol=1e-6)


def test_cartopy_backcompat():
import matplotlib
import matplotlib.axes
import matplotlib.axes._subplots

class Dummy(matplotlib.axes.Axes):
...

class DummySubplot(matplotlib.axes.SubplotBase, Dummy):
_axes_class = Dummy

matplotlib.axes._subplots._subplot_classes[Dummy] = DummySubplot

FactoryDummySubplot = matplotlib.axes.subplot_class_factory(Dummy)

assert DummySubplot is FactoryDummySubplot
Morty Proxy This is a proxified and sanitized view of the page, visit original site.