-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Single axes artist #3835
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
Single axes artist #3835
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Prevent moving artists between Axes, Property-ify Artist.axes, deprecate Artist.{get,set}_axes | ||
`````````````````````````````````````````````````````````````````````````````````````````````` | ||
|
||
The reason this was done was to prevent adding an Artist that is | ||
already associated with an Axes to be moved/added to a different Axes. | ||
This was never supported as it causes havoc with the transform stack. | ||
The apparent support for this (as it did not raise an exception) was | ||
the source of multiple bug reports and questions on SO. | ||
|
||
For almost all use-cases, the assignment of the axes to an artist should be | ||
taken care of by the axes as part of the ``Axes.add_*`` method, hence the | ||
deprecation {get,set}_axes. | ||
|
||
Removing the ``set_axes`` method will also remove the 'axes' line from | ||
the ACCEPTS kwarg tables (assuming that the removal date gets here | ||
before that gets overhauled). |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import inspect | ||
import matplotlib | ||
import matplotlib.cbook as cbook | ||
from matplotlib.cbook import mplDeprecation | ||
from matplotlib import docstring, rcParams | ||
from .transforms import (Bbox, IdentityTransform, TransformedBbox, | ||
TransformedPath, Transform) | ||
|
@@ -77,6 +78,7 @@ class Artist(object): | |
zorder = 0 | ||
|
||
def __init__(self): | ||
self._axes = None | ||
self.figure = None | ||
|
||
self._transform = None | ||
|
@@ -175,17 +177,43 @@ def set_axes(self, axes): | |
Set the :class:`~matplotlib.axes.Axes` instance in which the | ||
artist resides, if any. | ||
|
||
This has been deprecated in mpl 1.5, please use the | ||
axes property. Will be removed in 1.7 or 2.0. | ||
|
||
ACCEPTS: an :class:`~matplotlib.axes.Axes` instance | ||
""" | ||
warnings.warn(_get_axes_msg, mplDeprecation, stacklevel=1) | ||
self.axes = axes | ||
|
||
def get_axes(self): | ||
""" | ||
Return the :class:`~matplotlib.axes.Axes` instance the artist | ||
resides in, or *None* | ||
resides in, or *None*. | ||
|
||
This has been deprecated in mpl 1.5, please use the | ||
axes property. Will be removed in 1.7 or 2.0. | ||
""" | ||
warnings.warn(_get_axes_msg, mplDeprecation, stacklevel=1) | ||
return self.axes | ||
|
||
@property | ||
def axes(self): | ||
""" | ||
The :class:`~matplotlib.axes.Axes` instance the artist | ||
resides in, or *None*. | ||
""" | ||
return self._axes | ||
|
||
@axes.setter | ||
def axes(self, new_axes): | ||
if self._axes is not None and new_axes != self._axes: | ||
raise ValueError("Can not reset the axes. You are " | ||
"probably trying to re-use an artist " | ||
"in more than one Axes which is not " | ||
"supported") | ||
self._axes = new_axes | ||
return new_axes | ||
|
||
def get_window_extent(self, renderer): | ||
""" | ||
Get the axes bounding box in display space. | ||
|
@@ -751,10 +779,13 @@ def update(self, props): | |
changed = False | ||
|
||
for k, v in six.iteritems(props): | ||
func = getattr(self, 'set_' + k, None) | ||
if func is None or not six.callable(func): | ||
raise AttributeError('Unknown property %s' % k) | ||
func(v) | ||
if k in ['axes']: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why use this "in" test when the list has only one entry? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forward planning for when more of the |
||
setattr(self, k, v) | ||
else: | ||
func = getattr(self, 'set_' + k, None) | ||
if func is None or not six.callable(func): | ||
raise AttributeError('Unknown property %s' % k) | ||
func(v) | ||
changed = True | ||
self.eventson = store | ||
if changed: | ||
|
@@ -1328,3 +1359,6 @@ def kwdoc(a): | |
return '\n'.join(ArtistInspector(a).pprint_setters(leadingspace=2)) | ||
|
||
docstring.interpd.update(Artist=kwdoc(Artist)) | ||
|
||
_get_axes_msg = """This has been deprecated in mpl 1.5, please use the | ||
axes property. A removal date has not been set.""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -298,7 +298,11 @@ def __init__(self, | |
Defaults to rc ``figure.autolayout``. | ||
""" | ||
Artist.__init__(self) | ||
|
||
# remove the non-figure artist _axes property | ||
# as it makes no sense for a figure to be _in_ an axes | ||
# this is used by the property methods in the artist base class | ||
# which are over-ridden in this class | ||
del self._axes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it also make sense then to remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It already re-defines the property on https://github.com/matplotlib/matplotlib/pull/3835/files#diff-c3ce78ddcc28c54e04ade080c149c1b1R397 where it is overloaded to mean 'the list of axes this figure contains'. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops! Of course... |
||
self.callbacks = cbook.CallbackRegistry() | ||
|
||
if figsize is None: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% comfortable with the deprecation. It is a fairly major API chance, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am ok with it. I am wary of the open-ended schedule for removal, though. It would be better to simply schedule its removal a few releases from now, even if we can be a little bit vague on the exact release number at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I view this as an implementation detail which should only be called from the
add_*
methods on Axes (by c++ background is leaking through, Axes and Artist are friends) and probably never should have been part of the public API to begin with.I was being as hedgey as possible in the removal date, I am in favor of doing it as soon as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
property becomes
_axes
then?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exposing it read-only probably is useful, maybe the setter method should be turned into
_set_axes
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into removing the setter and using a
_set_axes
instead and it touches a lot of places where we currently just reach and touch the attribute.