|
8 | 8 | import inspect
|
9 | 9 | import matplotlib
|
10 | 10 | import matplotlib.cbook as cbook
|
| 11 | +from matplotlib.cbook import mplDeprecation |
11 | 12 | from matplotlib import docstring, rcParams
|
12 | 13 | from .transforms import (Bbox, IdentityTransform, TransformedBbox,
|
13 | 14 | TransformedPath, Transform)
|
@@ -77,6 +78,7 @@ class Artist(object):
|
77 | 78 | zorder = 0
|
78 | 79 |
|
79 | 80 | def __init__(self):
|
| 81 | + self._axes = None |
80 | 82 | self.figure = None
|
81 | 83 |
|
82 | 84 | self._transform = None
|
@@ -175,17 +177,43 @@ def set_axes(self, axes):
|
175 | 177 | Set the :class:`~matplotlib.axes.Axes` instance in which the
|
176 | 178 | artist resides, if any.
|
177 | 179 |
|
| 180 | + This has been deprecated in mpl 1.5, please use the |
| 181 | + axes property. Will be removed in 1.7 or 2.0. |
| 182 | +
|
178 | 183 | ACCEPTS: an :class:`~matplotlib.axes.Axes` instance
|
179 | 184 | """
|
| 185 | + warnings.warn(_get_axes_msg, mplDeprecation, stacklevel=1) |
180 | 186 | self.axes = axes
|
181 | 187 |
|
182 | 188 | def get_axes(self):
|
183 | 189 | """
|
184 | 190 | Return the :class:`~matplotlib.axes.Axes` instance the artist
|
185 |
| - resides in, or *None* |
| 191 | + resides in, or *None*. |
| 192 | +
|
| 193 | + This has been deprecated in mpl 1.5, please use the |
| 194 | + axes property. Will be removed in 1.7 or 2.0. |
186 | 195 | """
|
| 196 | + warnings.warn(_get_axes_msg, mplDeprecation, stacklevel=1) |
187 | 197 | return self.axes
|
188 | 198 |
|
| 199 | + @property |
| 200 | + def axes(self): |
| 201 | + """ |
| 202 | + The :class:`~matplotlib.axes.Axes` instance the artist |
| 203 | + resides in, or *None*. |
| 204 | + """ |
| 205 | + return self._axes |
| 206 | + |
| 207 | + @axes.setter |
| 208 | + def axes(self, new_axes): |
| 209 | + if self._axes is not None and new_axes != self._axes: |
| 210 | + raise ValueError("Can not reset the axes. You are " |
| 211 | + "probably trying to re-use an artist " |
| 212 | + "in more than one Axes which is not " |
| 213 | + "supported") |
| 214 | + self._axes = new_axes |
| 215 | + return new_axes |
| 216 | + |
189 | 217 | def get_window_extent(self, renderer):
|
190 | 218 | """
|
191 | 219 | Get the axes bounding box in display space.
|
@@ -751,10 +779,13 @@ def update(self, props):
|
751 | 779 | changed = False
|
752 | 780 |
|
753 | 781 | for k, v in six.iteritems(props):
|
754 |
| - func = getattr(self, 'set_' + k, None) |
755 |
| - if func is None or not six.callable(func): |
756 |
| - raise AttributeError('Unknown property %s' % k) |
757 |
| - func(v) |
| 782 | + if k in ['axes']: |
| 783 | + setattr(self, k, v) |
| 784 | + else: |
| 785 | + func = getattr(self, 'set_' + k, None) |
| 786 | + if func is None or not six.callable(func): |
| 787 | + raise AttributeError('Unknown property %s' % k) |
| 788 | + func(v) |
758 | 789 | changed = True
|
759 | 790 | self.eventson = store
|
760 | 791 | if changed:
|
@@ -1328,3 +1359,6 @@ def kwdoc(a):
|
1328 | 1359 | return '\n'.join(ArtistInspector(a).pprint_setters(leadingspace=2))
|
1329 | 1360 |
|
1330 | 1361 | docstring.interpd.update(Artist=kwdoc(Artist))
|
| 1362 | + |
| 1363 | +_get_axes_msg = """This has been deprecated in mpl 1.5, please use the |
| 1364 | +axes property. A removal date has not been set.""" |
0 commit comments