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

Skip to content

Commit 4764452

Browse files
authored
Merge pull request #16576 from anntzer/axesclassfactory-default
Deprecate arg-less calls to subplot_class_factory (and similar factories)
2 parents 1143143 + 479b8f8 commit 4764452

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,12 @@ Axis and Locator ``pan`` and ``zoom``
317317
The unused ``pan`` and ``zoom`` methods of `~.axis.Axis` and `~.ticker.Locator`
318318
are deprecated. Panning and zooming are now implemented using the
319319
``start_pan``, ``drag_pan``, and ``end_pan`` methods of `~.axes.Axes`.
320+
321+
Passing None to various Axes subclass factories
322+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
323+
Support for passing ``None`` as base class to `.axes.subplot_class_factory`,
324+
``axes_grid1.parasite_axes.host_axes_class_factory``,
325+
``axes_grid1.parasite_axes.host_subplot_class_factory``,
326+
``axes_grid1.parasite_axes.parasite_axes_class_factory``, and
327+
``axes_grid1.parasite_axes.parasite_axes_auxtrans_class_factory`` is deprecated.
328+
Explicitly pass the correct base ``Axes`` class instead.

lib/matplotlib/axes/_subplots.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ def subplot_class_factory(axes_class=None):
186186
not have to be created for every type of Axes.
187187
"""
188188
if axes_class is None:
189+
cbook.warn_deprecated(
190+
"3.3", message="Support for passing None to subplot_class_factory "
191+
"is deprecated; explicitly pass the default Axes class instead.")
189192
axes_class = Axes
190193
try:
191194
# Avoid creating two different instances of GeoAxesSubplot...
@@ -199,8 +202,7 @@ def subplot_class_factory(axes_class=None):
199202
{'_axes_class': axes_class})
200203

201204

202-
# This is provided for backward compatibility
203-
Subplot = subplot_class_factory()
205+
Subplot = subplot_class_factory(Axes) # Provided for backward compatibility.
204206

205207

206208
def _picklable_subplot_class_constructor(axes_class):

lib/mpl_toolkits/axes_grid1/parasite_axes.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,17 @@ def pick(self, mouseevent):
5252
@functools.lru_cache(None)
5353
def parasite_axes_class_factory(axes_class=None):
5454
if axes_class is None:
55+
cbook.warn_deprecated(
56+
"3.3", message="Support for passing None to "
57+
"parasite_axes_class_factory is deprecated; explicitly pass the "
58+
"default Axes class instead.")
5559
axes_class = Axes
5660

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

6064

61-
ParasiteAxes = parasite_axes_class_factory()
65+
ParasiteAxes = parasite_axes_class_factory(Axes)
6266

6367

6468
class ParasiteAxesAuxTransBase:
@@ -175,6 +179,10 @@ def apply_aspect(self, position=None):
175179
@functools.lru_cache(None)
176180
def parasite_axes_auxtrans_class_factory(axes_class=None):
177181
if axes_class is None:
182+
cbook.warn_deprecated(
183+
"3.3", message="Support for passing None to "
184+
"parasite_axes_auxtrans_class_factory is deprecated; explicitly "
185+
"pass the default ParasiteAxes class instead.")
178186
parasite_axes_class = ParasiteAxes
179187
elif not issubclass(axes_class, ParasiteAxesBase):
180188
parasite_axes_class = parasite_axes_class_factory(axes_class)
@@ -185,16 +193,15 @@ def parasite_axes_auxtrans_class_factory(axes_class=None):
185193
{'name': 'parasite_axes'})
186194

187195

188-
ParasiteAxesAuxTrans = parasite_axes_auxtrans_class_factory(
189-
axes_class=ParasiteAxes)
196+
ParasiteAxesAuxTrans = parasite_axes_auxtrans_class_factory(ParasiteAxes)
190197

191198

192199
class HostAxesBase:
193200
def __init__(self, *args, **kwargs):
194201
self.parasites = []
195202
super().__init__(*args, **kwargs)
196203

197-
def get_aux_axes(self, tr, viewlim_mode="equal", axes_class=None):
204+
def get_aux_axes(self, tr, viewlim_mode="equal", axes_class=ParasiteAxes):
198205
parasite_axes_class = parasite_axes_auxtrans_class_factory(axes_class)
199206
ax2 = parasite_axes_class(self, tr, viewlim_mode)
200207
# note that ax2.transData == tr + ax1.transData
@@ -354,6 +361,9 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
354361
@functools.lru_cache(None)
355362
def host_axes_class_factory(axes_class=None):
356363
if axes_class is None:
364+
cbook.warn_deprecated(
365+
"3.3", message="Support for passing None to host_axes_class is "
366+
"deprecated; explicitly pass the default Axes class instead.")
357367
axes_class = Axes
358368

359369
def _get_base_axes(self):
@@ -365,16 +375,16 @@ def _get_base_axes(self):
365375

366376

367377
def host_subplot_class_factory(axes_class):
368-
host_axes_class = host_axes_class_factory(axes_class=axes_class)
378+
host_axes_class = host_axes_class_factory(axes_class)
369379
subplot_host_class = subplot_class_factory(host_axes_class)
370380
return subplot_host_class
371381

372382

373-
HostAxes = host_axes_class_factory(axes_class=Axes)
383+
HostAxes = host_axes_class_factory(Axes)
374384
SubplotHost = subplot_class_factory(HostAxes)
375385

376386

377-
def host_axes(*args, axes_class=None, figure=None, **kwargs):
387+
def host_axes(*args, axes_class=Axes, figure=None, **kwargs):
378388
"""
379389
Create axes that can act as a hosts to parasitic axes.
380390
@@ -397,7 +407,7 @@ def host_axes(*args, axes_class=None, figure=None, **kwargs):
397407
return ax
398408

399409

400-
def host_subplot(*args, axes_class=None, figure=None, **kwargs):
410+
def host_subplot(*args, axes_class=Axes, figure=None, **kwargs):
401411
"""
402412
Create a subplot that can act as a host to parasitic axes.
403413

0 commit comments

Comments
 (0)