-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
WIP: Lockout new converters Part 2 #9776
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 |
---|---|---|
|
@@ -7,9 +7,10 @@ | |
from six.moves import xrange | ||
|
||
import itertools | ||
import warnings | ||
import logging | ||
import math | ||
from operator import attrgetter | ||
import warnings | ||
|
||
import numpy as np | ||
|
||
|
@@ -38,6 +39,8 @@ | |
from matplotlib.rcsetup import cycler | ||
from matplotlib.rcsetup import validate_axisbelow | ||
|
||
_log = logging.getLogger(__name__) | ||
|
||
rcParams = matplotlib.rcParams | ||
|
||
is_string_like = cbook.is_string_like | ||
|
@@ -1002,7 +1005,7 @@ def cla(self): | |
else: | ||
self.xaxis._set_scale('linear') | ||
try: | ||
self.set_xlim(0, 1) | ||
self.set_xlim(0, 1, _converter=False) | ||
except TypeError: | ||
pass | ||
|
||
|
@@ -1016,7 +1019,7 @@ def cla(self): | |
else: | ||
self.yaxis._set_scale('linear') | ||
try: | ||
self.set_ylim(0, 1) | ||
self.set_ylim(0, 1, _converter=False) | ||
except TypeError: | ||
pass | ||
|
||
|
@@ -2377,6 +2380,7 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True): | |
case, use :meth:`matplotlib.axes.Axes.relim` prior to calling | ||
autoscale_view. | ||
""" | ||
_log.debug('Autoscaling x: %s y: %s', scalex, scaley) | ||
if tight is not None: | ||
self._tight = bool(tight) | ||
|
||
|
@@ -2446,6 +2450,7 @@ def handle_single_axis(scale, autoscaleon, shared_axes, interval, | |
|
||
if not self._tight: | ||
x0, x1 = locator.view_limits(x0, x1) | ||
_log.debug('Autolims: %e %e', x0, x1) | ||
set_bound(x0, x1) | ||
# End of definition of internal function 'handle_single_axis'. | ||
|
||
|
@@ -2923,6 +2928,7 @@ def set_xbound(self, lower=None, upper=None): | |
self.set_xlim(upper, lower, auto=None) | ||
else: | ||
self.set_xlim(lower, upper, auto=None) | ||
self.set_xlim(lower, upper, auto=None) | ||
else: | ||
if lower < upper: | ||
self.set_xlim(lower, upper, auto=None) | ||
|
@@ -3028,15 +3034,19 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw): | |
left = kw.pop('xmin') | ||
if 'xmax' in kw: | ||
right = kw.pop('xmax') | ||
# _converter is private, usually True, but can be false | ||
_converter = kw.pop('_converter', True) | ||
if kw: | ||
raise ValueError("unrecognized kwargs: %s" % list(kw)) | ||
|
||
if right is None and iterable(left): | ||
left, right = left | ||
|
||
self._process_unit_info(xdata=(left, right)) | ||
left = self._validate_converted_limits(left, self.convert_xunits) | ||
right = self._validate_converted_limits(right, self.convert_xunits) | ||
if _converter: | ||
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. What's the purpose of this if statement? 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. As above. Its because |
||
_log.debug('Converting xlim %s %s', left, right) | ||
self._process_unit_info(xdata=(left, right)) | ||
left = self._validate_converted_limits(left, self.convert_xunits) | ||
right = self._validate_converted_limits(right, self.convert_xunits) | ||
|
||
old_left, old_right = self.get_xlim() | ||
if left is None: | ||
|
@@ -3352,14 +3362,20 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw): | |
bottom = kw.pop('ymin') | ||
if 'ymax' in kw: | ||
top = kw.pop('ymax') | ||
_converter = kw.pop('_converter', True) | ||
if kw: | ||
raise ValueError("unrecognized kwargs: %s" % list(kw)) | ||
|
||
if top is None and iterable(bottom): | ||
bottom, top = bottom | ||
|
||
bottom = self._validate_converted_limits(bottom, self.convert_yunits) | ||
top = self._validate_converted_limits(top, self.convert_yunits) | ||
if _converter: | ||
_log.debug('Converting ylim %s %s', bottom, top) | ||
self._process_unit_info(ydata=(bottom, top)) | ||
bottom = self._validate_converted_limits(bottom, | ||
self.convert_yunits) | ||
top = self._validate_converted_limits(top, | ||
self.convert_yunits) | ||
|
||
old_bottom, old_top = self.get_ylim() | ||
|
||
|
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.
Can kwargs be private? (I've never seen this before so I have no idea)
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.
From a philosophical standpoint, nothing can be private in the panopticon that is Python symbol visibility, but here is an example from pytz of a private kwarg (though I think popping it from
**kwargs
so it doesn't show up under inspection is a better course to take).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 think it is pretty clear that a kwarg with an underscore is intended as private.
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.
Maybe the better question is, will an underscored kwarg appear in the documentation? (I'm not convinced in this case that the kwarg is needed anyway)
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.
@dstansby Looks to me like the way it's implemented, it's just being pulled from the
kwargs
dictionary, it's not an actual declared keyword argument, so you'd need a pretty smart document generator to even figure out that passing_converter
to this would be meaningful.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.
Just to justify this kwarg - the point of this PR is that the first time you conver units on an axis, the converter gets set. This happens on
set_xticks
,set_xlims
or any of the plotting calls.cla
callsset_xlim
but its not doing so because it has any data that might have units. So this kwarg is just an easy way to say "set the limit, but don't assign the units because this is just a placeholder".We could, alternately, make a new method (
_set_xlim_placeholder
) that did the same thing, if that is better than a hidden kwarg?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 think either way is fine.