-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Deprecate setting Axis.major.locator to non-Locator; idem for Formatters #13851
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
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,8 @@ | ||
Deprecations | ||
```````````` | ||
|
||
Setting ``Axis.major.locator``, ``Axis.minor.locator``, ``Axis.major.formatter`` | ||
or ``Axis.minor.formatter`` to an object that is not a subclass of `Locator` or | ||
`Formatter` (respectively) is deprecated. Note that these attributes should | ||
usually be set using `Axis.set_major_locator`, `Axis.set_minor_locator`, etc. | ||
which already raise an exception when an object of the wrong class is passed. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -640,8 +640,36 @@ class Ticker(object): | |
formatter : `matplotlib.ticker.Formatter` subclass | ||
Determines the format of the tick labels. | ||
""" | ||
locator = None | ||
formatter = None | ||
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. I hope that removing these (public) class attributes isn't going to trip anyone up. Maybe that would involve such an obscure use case that it won't happen. 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. We did just have that issue, but in this case I suspect it will be ok. These lines go back to d78e6c4 and I suspect it was done done to make sure that |
||
|
||
def __init__(self): | ||
self._locator = None | ||
self._formatter = None | ||
|
||
@property | ||
def locator(self): | ||
return self._locator | ||
|
||
@locator.setter | ||
def locator(self, locator): | ||
if not isinstance(locator, mticker.Locator): | ||
cbook.warn_deprecated( | ||
"3.2", message="Support for locators that do not subclass " | ||
"matplotlib.ticker.Locator is deprecated since %(since)s and " | ||
"support for them will be removed %(removal)s.") | ||
self._locator = locator | ||
|
||
@property | ||
def formatter(self): | ||
return self._formatter | ||
|
||
@formatter.setter | ||
def formatter(self, formatter): | ||
if not isinstance(formatter, mticker.Formatter): | ||
cbook.warn_deprecated( | ||
"3.2", message="Support for formatters that do not subclass " | ||
"matplotlib.ticker.Formatter is deprecated since %(since)s " | ||
"and support for them will be removed %(removal)s.") | ||
self._formatter = formatter | ||
|
||
|
||
class _LazyTickList(object): | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
Should they be set at all directly on the ticker? I don't think so at least for locators, because
Axis.set_major_locator
ensures that the formatter knows the locator, which is not guaranteed when settingAxis.major.locator
.So maybe add
_set_locator()
and_set_formatter()
for the internal API. And deprecate property setter for all inputs.Uh oh!
There was an error while loading. Please reload this page.
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.
Well, you get to argue about https://github.com/matplotlib/matplotlib/pull/13826/files#diff-52127080e2783464f529df684d82d476R1319 with @tacaswell then :)
(Note that we could move the call to
_set_locator
inlocator.setter
, though.)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 don't see the point. The linked diff does not assign to
axis.major.locator
oraxis.major.formatter
?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.
It does
getattr(self.minor.locator, "remove_overlaps", True)
instead of the simplerself.minor.locator.remove_overlaps
(note thatremove_overlaps
is in the base Locator class) specifically to handle the case of a locator not inheriting from Locator.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.
Ok, I see that we jump through some hoops to support non-Locator instances as locator.
But
_set_locator()
would be living inTickHelper
, which hopefully nobody has replaced. AFAICS non-Locator objects would still work.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.
Sorry, I don't get what you're saying about TickHelper. Did you mean Ticker (which is not the same)?