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

Skip to content

Deprecate arg-less calls to subplot_class_factory (and similar factories) #16576

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 1 commit into from
Mar 11, 2020
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
9 changes: 9 additions & 0 deletions doc/api/next_api_changes/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,12 @@ Axis and Locator ``pan`` and ``zoom``
The unused ``pan`` and ``zoom`` methods of `~.axis.Axis` and `~.ticker.Locator`
are deprecated. Panning and zooming are now implemented using the
``start_pan``, ``drag_pan``, and ``end_pan`` methods of `~.axes.Axes`.

Passing None to various Axes subclass factories
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Support for passing ``None`` as base class to `.axes.subplot_class_factory`,
``axes_grid1.parasite_axes.host_axes_class_factory``,
``axes_grid1.parasite_axes.host_subplot_class_factory``,
``axes_grid1.parasite_axes.parasite_axes_class_factory``, and
``axes_grid1.parasite_axes.parasite_axes_auxtrans_class_factory`` is deprecated.
Explicitly pass the correct base ``Axes`` class instead.
6 changes: 4 additions & 2 deletions lib/matplotlib/axes/_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ def subplot_class_factory(axes_class=None):
not have to be created for every type of Axes.
"""
if axes_class is None:
cbook.warn_deprecated(
"3.3", message="Support for passing None to subplot_class_factory "
Copy link
Member

@QuLogic QuLogic Mar 11, 2020

Choose a reason for hiding this comment

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

Same thing about the alignment here (and below) as the other PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

at least for deprecations this pattern is common through the codebase, as can be checked with git grep -A2 'message=')

"is deprecated; explicitly pass the default Axes class instead.")
axes_class = Axes
try:
# Avoid creating two different instances of GeoAxesSubplot...
Expand All @@ -199,8 +202,7 @@ def subplot_class_factory(axes_class=None):
{'_axes_class': axes_class})


# This is provided for backward compatibility
Subplot = subplot_class_factory()
Subplot = subplot_class_factory(Axes) # Provided for backward compatibility.


def _picklable_subplot_class_constructor(axes_class):
Expand Down
26 changes: 18 additions & 8 deletions lib/mpl_toolkits/axes_grid1/parasite_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ def pick(self, mouseevent):
@functools.lru_cache(None)
def parasite_axes_class_factory(axes_class=None):
if axes_class is None:
cbook.warn_deprecated(
"3.3", message="Support for passing None to "
"parasite_axes_class_factory is deprecated; explicitly pass the "
"default Axes class instead.")
axes_class = Axes

return type("%sParasite" % axes_class.__name__,
(ParasiteAxesBase, axes_class), {})


ParasiteAxes = parasite_axes_class_factory()
ParasiteAxes = parasite_axes_class_factory(Axes)


class ParasiteAxesAuxTransBase:
Expand Down Expand Up @@ -175,6 +179,10 @@ def apply_aspect(self, position=None):
@functools.lru_cache(None)
def parasite_axes_auxtrans_class_factory(axes_class=None):
if axes_class is None:
cbook.warn_deprecated(
"3.3", message="Support for passing None to "
"parasite_axes_auxtrans_class_factory is deprecated; explicitly "
"pass the default ParasiteAxes class instead.")
parasite_axes_class = ParasiteAxes
elif not issubclass(axes_class, ParasiteAxesBase):
parasite_axes_class = parasite_axes_class_factory(axes_class)
Expand All @@ -185,16 +193,15 @@ def parasite_axes_auxtrans_class_factory(axes_class=None):
{'name': 'parasite_axes'})


ParasiteAxesAuxTrans = parasite_axes_auxtrans_class_factory(
axes_class=ParasiteAxes)
ParasiteAxesAuxTrans = parasite_axes_auxtrans_class_factory(ParasiteAxes)


class HostAxesBase:
def __init__(self, *args, **kwargs):
self.parasites = []
super().__init__(*args, **kwargs)

def get_aux_axes(self, tr, viewlim_mode="equal", axes_class=None):
def get_aux_axes(self, tr, viewlim_mode="equal", axes_class=ParasiteAxes):
parasite_axes_class = parasite_axes_auxtrans_class_factory(axes_class)
ax2 = parasite_axes_class(self, tr, viewlim_mode)
# note that ax2.transData == tr + ax1.transData
Expand Down Expand Up @@ -354,6 +361,9 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
@functools.lru_cache(None)
def host_axes_class_factory(axes_class=None):
if axes_class is None:
cbook.warn_deprecated(
"3.3", message="Support for passing None to host_axes_class is "
"deprecated; explicitly pass the default Axes class instead.")
axes_class = Axes

def _get_base_axes(self):
Expand All @@ -365,16 +375,16 @@ def _get_base_axes(self):


def host_subplot_class_factory(axes_class):
host_axes_class = host_axes_class_factory(axes_class=axes_class)
host_axes_class = host_axes_class_factory(axes_class)
subplot_host_class = subplot_class_factory(host_axes_class)
return subplot_host_class


HostAxes = host_axes_class_factory(axes_class=Axes)
HostAxes = host_axes_class_factory(Axes)
SubplotHost = subplot_class_factory(HostAxes)


def host_axes(*args, axes_class=None, figure=None, **kwargs):
def host_axes(*args, axes_class=Axes, figure=None, **kwargs):
"""
Create axes that can act as a hosts to parasitic axes.

Expand All @@ -397,7 +407,7 @@ def host_axes(*args, axes_class=None, figure=None, **kwargs):
return ax


def host_subplot(*args, axes_class=None, figure=None, **kwargs):
def host_subplot(*args, axes_class=Axes, figure=None, **kwargs):
"""
Create a subplot that can act as a host to parasitic axes.

Expand Down