-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
[MNT]: Implement Scale.val_in_range and refactor _point_in_data_domain
#31306
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 5 commits
c3df005
f91d2b4
926c259
e3dc7b7
6feeec1
631a52f
d62a69f
59bd52b
6d03949
b78b003
3de6b1f
c35268f
6b820a8
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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -113,6 +113,17 @@ | |||||||||||||||||
| This is used by log scales to determine a minimum value. | ||||||||||||||||||
| """ | ||||||||||||||||||
| return vmin, vmax | ||||||||||||||||||
|
|
||||||||||||||||||
|
Check warning on line 116 in lib/matplotlib/scale.py
|
||||||||||||||||||
| def val_in_range(self, val): | ||||||||||||||||||
| """ | ||||||||||||||||||
| Return whether the value(s) are within the valid range for this scale. | ||||||||||||||||||
| """ | ||||||||||||||||||
|
Comment on lines
+120
to
+124
Member
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.
Suggested change
|
||||||||||||||||||
| if np.isscalar(val): | ||||||||||||||||||
| vmin, vmax = self.limit_range_for_scale(val, val, minpos=1e-300) | ||||||||||||||||||
| return (vmax == val) and (vmin == val) | ||||||||||||||||||
|
|
||||||||||||||||||
| val = np.asanyarray(val) | ||||||||||||||||||
| return np.array([self.val_in_range(v) for v in val]) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def _make_axis_parameter_optional(init_func): | ||||||||||||||||||
|
|
@@ -195,6 +206,13 @@ | |||||||||||||||||
| `~matplotlib.transforms.IdentityTransform`. | ||||||||||||||||||
| """ | ||||||||||||||||||
| return IdentityTransform() | ||||||||||||||||||
|
|
||||||||||||||||||
|
Check warning on line 209 in lib/matplotlib/scale.py
|
||||||||||||||||||
| def val_in_range(self, val): | ||||||||||||||||||
| """ | ||||||||||||||||||
| Return `True` for all values. | ||||||||||||||||||
| """ | ||||||||||||||||||
|
Comment on lines
+217
to
+221
Member
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. The docstring should always descripe the concept, not just the imlementation. A docstring def some_func():
"""Return True."""
return Truehas zero information conent. Instead do:
Suggested change
The first sentence should be in all
Contributor
Author
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. This was actually pretty enlightening. Kind of changed the way I thought about docstrings. |
||||||||||||||||||
| val = np.asanyarray(val) | ||||||||||||||||||
| return np.ones(val.shape, dtype=bool) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| class FuncTransform(Transform): | ||||||||||||||||||
|
|
@@ -399,6 +417,10 @@ | |||||||||||||||||
|
|
||||||||||||||||||
| return (minpos if vmin <= 0 else vmin, | ||||||||||||||||||
| minpos if vmax <= 0 else vmax) | ||||||||||||||||||
|
|
||||||||||||||||||
|
Check warning on line 420 in lib/matplotlib/scale.py
|
||||||||||||||||||
| def val_in_range(self, val): | ||||||||||||||||||
| """Return `True` for positive values.""" | ||||||||||||||||||
| return np.asanyarray(val) > 0 | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| class FuncScaleLog(LogScale): | ||||||||||||||||||
|
|
@@ -819,6 +841,13 @@ | |||||||||||||||||
| minpos = 1e-7 # Should rarely (if ever) have a visible effect. | ||||||||||||||||||
| return (minpos if vmin <= 0 else vmin, | ||||||||||||||||||
| 1 - minpos if vmax >= 1 else vmax) | ||||||||||||||||||
|
|
||||||||||||||||||
|
Check warning on line 844 in lib/matplotlib/scale.py
|
||||||||||||||||||
| def val_in_range(self, val): | ||||||||||||||||||
| """ | ||||||||||||||||||
| Return `True` if value(s) lie between 0 and 1 (excluded) | ||||||||||||||||||
| """ | ||||||||||||||||||
| val = np.asanyarray(val) | ||||||||||||||||||
| return (val > 0) & (val < 1) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| _scale_mapping = { | ||||||||||||||||||
|
|
||||||||||||||||||
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.
What is the motivation to expose this on the Axis?
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 noticed
limit_range_in_scalebeing available in Axis class, so exposing theval_in_rangeseemed consistent to me. But I later forgot to implement the wrapper in_point_in_data_domain.I have two possible approaches here:
_point_in_data_domain._point_in_data_domain, using the_scaleattribute, unchanged.After going through other exposed apis, I feel removing the wrapper here would be fine as currently there is no other use of
val_in_rangeexcept in_point_in_data_domain.