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

Skip to content

Commit 2eb26ee

Browse files
authored
Merge pull request #10403 from QuLogic/deprecate-locatable-axes
Deprecate LocatableAxes from toolkits
2 parents 691fb7f + 7421b0e commit 2eb26ee

File tree

12 files changed

+86
-116
lines changed

12 files changed

+86
-116
lines changed

.flake8

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ per-file-ignores =
6161
matplotlib/type1font.py: E731
6262

6363
mpl_toolkits/__init__.py: E261
64-
mpl_toolkits/axes_grid/axes_divider.py: E501
65-
mpl_toolkits/axes_grid/axes_rgb.py: E302, E501
64+
mpl_toolkits/axes_grid/axes_rgb.py: E501
6665
mpl_toolkits/axes_grid1/axes_divider.py: E402, E501
6766
mpl_toolkits/axes_grid1/axes_grid.py: E225
6867
mpl_toolkits/axes_grid1/axes_rgb.py: E231
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Deprecation of ``LocatableAxes`` in toolkits
2+
--------------------------------------------
3+
4+
The ``LocatableAxes`` classes in toolkits have been deprecated. The base `Axes`
5+
classes provide the same functionality to all subclasses, thus these mixins are
6+
no longer necessary. Related functions have also been deprecated. Specifically:
7+
8+
* ``mpl_toolkits.axes_grid1.axes_divider.LocatableAxesBase``: no specific
9+
replacement; use any other ``Axes``-derived class directly instead.
10+
* ``mpl_toolkits.axes_grid1.axes_divider.locatable_axes_factory``: no specific
11+
replacement; use any other ``Axes``-derived class directly instead.
12+
* ``mpl_toolkits.axes_grid1.axes_divider.Axes``: use
13+
`mpl_toolkits.axes_grid1.mpl_axes.Axes` directly.
14+
* ``mpl_toolkits.axes_grid1.axes_divider.LocatableAxes``: use
15+
`mpl_toolkits.axes_grid1.mpl_axes.Axes` directly.
16+
* ``mpl_toolkits.axisartist.axes_divider.Axes``: use
17+
`mpl_toolkits.axisartist.axislines.Axes` directly.
18+
* ``mpl_toolkits.axisartist.axes_divider.LocatableAxes``: use
19+
`mpl_toolkits.axisartist.axislines.Axes` directly.

lib/mpl_toolkits/axes_grid/ChangeLog

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from mpl_toolkits.axes_grid1.axes_divider import Divider, AxesLocator, SubplotDivider, \
2-
AxesDivider, locatable_axes_factory, make_axes_locatable
3-
4-
from mpl_toolkits.axes_grid.axislines import Axes
5-
LocatableAxes = locatable_axes_factory(Axes)
1+
from mpl_toolkits.axes_grid1.axes_divider import (
2+
AxesDivider, AxesLocator, Divider, SubplotDivider, locatable_axes_factory,
3+
make_axes_locatable)
4+
from mpl_toolkits.axisartist.axes_divider import LocatableAxes
5+
from mpl_toolkits.axisartist.axislines import Axes
Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,3 @@
1-
import mpl_toolkits.axes_grid1.axes_grid as axes_grid_orig
2-
from .axes_divider import LocatableAxes
3-
4-
5-
class CbarAxes(axes_grid_orig.CbarAxesBase, LocatableAxes):
6-
def __init__(self, *args, orientation, **kwargs):
7-
self.orientation = orientation
8-
self._default_label_on = False
9-
self.locator = None
10-
super().__init__(*args, **kwargs)
11-
12-
def cla(self):
13-
super().cla()
14-
self._config_axes()
15-
16-
17-
class Grid(axes_grid_orig.Grid):
18-
_defaultLocatableAxesClass = LocatableAxes
19-
20-
21-
class ImageGrid(axes_grid_orig.ImageGrid):
22-
_defaultLocatableAxesClass = LocatableAxes
23-
_defaultCbarAxesClass = CbarAxes
24-
25-
26-
AxesGrid = ImageGrid
1+
from mpl_toolkits.axisartist.axes_divider import LocatableAxes
2+
from mpl_toolkits.axisartist.axes_grid import (
3+
AxesGrid, CbarAxes, Grid, ImageGrid)

lib/mpl_toolkits/axes_grid/axes_rgb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from mpl_toolkits.axes_grid1.axes_rgb import make_rgb_axes, imshow_rgb, RGBAxesBase
33

44
#import mpl_toolkits.axes_grid1.axes_rgb as axes_rgb_orig
5-
from .axislines import Axes
5+
from mpl_toolkits.axisartist.axislines import Axes
6+
67

78
class RGBAxes(RGBAxesBase):
89
_defaultAxesClass = Axes

lib/mpl_toolkits/axes_grid/parasite_axes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from mpl_toolkits.axes_grid1.parasite_axes import (
22
host_axes_class_factory, parasite_axes_class_factory,
33
parasite_axes_auxtrans_class_factory, subplot_class_factory)
4-
5-
from .axislines import Axes
4+
from mpl_toolkits.axisartist.axislines import Axes
65

76

87
ParasiteAxes = parasite_axes_class_factory(Axes)

lib/mpl_toolkits/axes_grid1/axes_divider.py

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import functools
1414

1515
import matplotlib.transforms as mtransforms
16+
from matplotlib import cbook
1617
from matplotlib.axes import SubplotBase
1718
from . import axes_size as Size
1819

@@ -863,62 +864,23 @@ def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
863864
return mtransforms.Bbox.from_bounds(x1, y1, w1, h1)
864865

865866

867+
@cbook.deprecated('3.0',
868+
addendum=' There is no alternative. Deriving from '
869+
'matplotlib.axes.Axes provides this functionality '
870+
'already.')
866871
class LocatableAxesBase(object):
867-
def __init__(self, *kl, **kw):
872+
pass
868873

869-
self._axes_class.__init__(self, *kl, **kw)
870874

871-
self._locator = None
872-
self._locator_renderer = None
873-
874-
def set_axes_locator(self, locator):
875-
self._locator = locator
876-
877-
def get_axes_locator(self):
878-
return self._locator
879-
880-
def apply_aspect(self, position=None):
881-
882-
if self.get_axes_locator() is None:
883-
self._axes_class.apply_aspect(self, position)
884-
else:
885-
pos = self.get_axes_locator()(self, self._locator_renderer)
886-
self._axes_class.apply_aspect(self, position=pos)
887-
888-
def draw(self, renderer=None, inframe=False):
889-
890-
self._locator_renderer = renderer
891-
892-
self._axes_class.draw(self, renderer, inframe)
893-
894-
def _make_twin_axes(self, *kl, **kwargs):
895-
"""
896-
Need to overload so that twinx/twiny will work with
897-
these axes.
898-
"""
899-
if 'sharex' in kwargs and 'sharey' in kwargs:
900-
raise ValueError("Twinned Axes may share only one axis.")
901-
ax2 = type(self)(self.figure, self.get_position(True), *kl, **kwargs)
902-
ax2.set_axes_locator(self.get_axes_locator())
903-
self.figure.add_axes(ax2)
904-
self.set_adjustable('datalim')
905-
ax2.set_adjustable('datalim')
906-
self._twinned_axes.join(self, ax2)
907-
return ax2
908-
909-
910-
@functools.lru_cache(None)
875+
@cbook.deprecated('3.0',
876+
addendum=' There is no alternative. Classes derived from '
877+
'matplotlib.axes.Axes provide this functionality '
878+
'already.')
911879
def locatable_axes_factory(axes_class):
912-
return type("Locatable%s" % axes_class.__name__,
913-
(LocatableAxesBase, axes_class),
914-
{'_axes_class': axes_class})
880+
return axes_class
915881

916882

917883
def make_axes_locatable(axes):
918-
if not hasattr(axes, "set_axes_locator"):
919-
new_class = locatable_axes_factory(type(axes))
920-
axes.__class__ = new_class
921-
922884
divider = AxesDivider(axes)
923885
locator = divider.new_locator(nx=0, ny=0)
924886
axes.set_axes_locator(locator)
@@ -939,6 +901,17 @@ def make_axes_area_auto_adjustable(ax,
939901
divider.add_auto_adjustable_area(use_axes=use_axes, pad=pad,
940902
adjust_dirs=adjust_dirs)
941903

942-
#from matplotlib.axes import Axes
943-
from .mpl_axes import Axes
944-
LocatableAxes = locatable_axes_factory(Axes)
904+
905+
from .mpl_axes import Axes as _Axes
906+
907+
908+
@cbook.deprecated('3.0',
909+
alternative='mpl_toolkits.axes_grid1.mpl_axes.Axes')
910+
class Axes(_Axes):
911+
pass
912+
913+
914+
@cbook.deprecated('3.0',
915+
alternative='mpl_toolkits.axes_grid1.mpl_axes.Axes')
916+
class LocatableAxes(_Axes):
917+
pass

lib/mpl_toolkits/axes_grid1/axes_grid.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import matplotlib.ticker as ticker
55
from matplotlib.gridspec import SubplotSpec
66

7-
from .axes_divider import Size, SubplotDivider, LocatableAxes, Divider
7+
from .axes_divider import Size, SubplotDivider, Divider
88
from .colorbar import Colorbar
9+
from .mpl_axes import Axes
910

1011

1112
def _extend_axes_pad(value):
@@ -100,7 +101,7 @@ def toggle_label(self, b):
100101
#axis.label.set_visible(b)
101102

102103

103-
class CbarAxes(CbarAxesBase, LocatableAxes):
104+
class CbarAxes(CbarAxesBase, Axes):
104105
def __init__(self, *args, orientation, **kwargs):
105106
self.orientation = orientation
106107
self._default_label_on = True
@@ -122,7 +123,7 @@ class Grid(object):
122123
be easily done in matplotlib. AxesGrid is used in such case.
123124
"""
124125

125-
_defaultLocatableAxesClass = LocatableAxes
126+
_defaultAxesClass = Axes
126127

127128
def __init__(self, fig,
128129
rect,
@@ -182,12 +183,12 @@ def __init__(self, fig,
182183
self._direction = direction
183184

184185
if axes_class is None:
185-
axes_class = self._defaultLocatableAxesClass
186+
axes_class = self._defaultAxesClass
186187
axes_class_args = {}
187188
else:
188189
if (isinstance(axes_class, type)
189190
and issubclass(axes_class,
190-
self._defaultLocatableAxesClass.Axes)):
191+
self._defaultAxesClass.Axes)):
191192
axes_class_args = {}
192193
else:
193194
axes_class, axes_class_args = axes_class
@@ -503,7 +504,7 @@ def __init__(self, fig,
503504
self._direction = direction
504505

505506
if axes_class is None:
506-
axes_class = self._defaultLocatableAxesClass
507+
axes_class = self._defaultAxesClass
507508
axes_class_args = {}
508509
else:
509510
if isinstance(axes_class, maxes.Axes):

lib/mpl_toolkits/axes_grid1/axes_rgb.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
2-
from .axes_divider import make_axes_locatable, Size, locatable_axes_factory
2+
3+
from .axes_divider import make_axes_locatable, Size
34
from .mpl_axes import Axes
45

56

@@ -23,9 +24,9 @@ def make_rgb_axes(ax, pad=0.01, axes_class=None, add_all=True):
2324
ax_rgb = []
2425
if axes_class is None:
2526
try:
26-
axes_class = locatable_axes_factory(ax._axes_class)
27+
axes_class = ax._axes_class
2728
except AttributeError:
28-
axes_class = locatable_axes_factory(type(ax))
29+
axes_class = type(ax)
2930

3031
for ny in [4, 2, 0]:
3132
ax1 = axes_class(ax.get_figure(),
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1+
from matplotlib import cbook
2+
13
from mpl_toolkits.axes_grid1.axes_divider import (
24
Divider, AxesLocator, SubplotDivider, AxesDivider, locatable_axes_factory,
35
make_axes_locatable)
46

5-
from mpl_toolkits.axes_grid.axislines import Axes
6-
LocatableAxes = locatable_axes_factory(Axes)
7+
from mpl_toolkits.axisartist.axislines import Axes as _Axes
8+
9+
10+
@cbook.deprecated('3.0',
11+
alternative='mpl_toolkits.axisartist.axislines.Axes')
12+
class Axes(_Axes):
13+
pass
14+
15+
16+
@cbook.deprecated('3.0',
17+
alternative='mpl_toolkits.axisartist.axislines.Axes')
18+
class LocatableAxes(_Axes):
19+
pass

lib/mpl_toolkits/axisartist/axes_grid.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import mpl_toolkits.axes_grid1.axes_grid as axes_grid_orig
2-
from .axes_divider import LocatableAxes
2+
from .axislines import Axes
33

44

5-
class CbarAxes(axes_grid_orig.CbarAxesBase, LocatableAxes):
5+
class CbarAxes(axes_grid_orig.CbarAxesBase, Axes):
66
def __init__(self, *args, orientation, **kwargs):
77
self.orientation = orientation
88
self._default_label_on = False
@@ -15,11 +15,11 @@ def cla(self):
1515

1616

1717
class Grid(axes_grid_orig.Grid):
18-
_defaultLocatableAxesClass = LocatableAxes
18+
_defaultAxesClass = Axes
1919

2020

2121
class ImageGrid(axes_grid_orig.ImageGrid):
22-
_defaultLocatableAxesClass = LocatableAxes
22+
_defaultAxesClass = Axes
2323
_defaultCbarAxesClass = CbarAxes
2424

2525

0 commit comments

Comments
 (0)