-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
DOC: Clarify description and add examples in colors.Normalize #26915
Conversation
Co-authored-by: Zihao Yang zihaoyng@gmail.com
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.
Looks useful. One small suggestion.
Co-authored-by: Zihao Yang zihaoyng@gmail.com
Updated with the suggestions. |
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.
Looks good, only minor comments.
lib/matplotlib/colors.py
Outdated
A class which, when called, maps data values within the interval | ||
``[vmin, vmax]`` linearly to fit within the interval ``[0.0, 1.0]``. Data | ||
with values outside ``[vmin, vmax]`` will be mapped based on *clip*. |
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.
Minor wording suggestions to be more concise (data values -> values, map to fit within the interval -> map to the interval, ...)
A class which, when called, maps data values within the interval | |
``[vmin, vmax]`` linearly to fit within the interval ``[0.0, 1.0]``. Data | |
with values outside ``[vmin, vmax]`` will be mapped based on *clip*. | |
A class which, when called, maps values within the interval | |
``[vmin, vmax]`` linearly to the interval ``[0.0, 1.0]``. The mapping of | |
values outside ``[vmin, vmax]`` depends on *clip*. |
lib/matplotlib/colors.py
Outdated
# [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0] | ||
x = np.linspace(0, 1, 11) | ||
|
||
norm = mpl.colors.Normalize(vmin=0.2, vmax=0.6, clip=False) | ||
norm(x) # [-0.5, -0.25, 0, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0] | ||
|
||
norm = mpl.colors.Normalize(vmin=0.2, vmax=0.6, clip=True) | ||
norm(x) # [0, 0, 0, 0.25, 0.5, 0.75, 1.0, 1.0, 1.0, 1.0, 1.0] |
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 may be confusing to choose the actual x
range to be [0, 1]
which is incidentally the target range of the Norm, but is completely unrelated. These numbers may make the effect more obvious
# [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0] | |
x = np.linspace(0, 1, 11) | |
norm = mpl.colors.Normalize(vmin=0.2, vmax=0.6, clip=False) | |
norm(x) # [-0.5, -0.25, 0, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0] | |
norm = mpl.colors.Normalize(vmin=0.2, vmax=0.6, clip=True) | |
norm(x) # [0, 0, 0, 0.25, 0.5, 0.75, 1.0, 1.0, 1.0, 1.0, 1.0] | |
x = [-2, -1, 0, 1, 2] | |
norm = mpl.colors.Normalize(vmin=-1, vmax=1, clip=False) | |
norm(x) # [-0.5, 0., 0.5, 1., 1.5] | |
norm = mpl.colors.Normalize(vmin=-1, vmax=1, clip=True) | |
norm(x) # [0., 0., 0.5, 1., 1.] |
lib/matplotlib/colors.py
Outdated
@@ -1410,7 +1444,7 @@ def autoscale_None(self, A): | |||
self.vmax = A.max() | |||
|
|||
def scaled(self): | |||
"""Return whether vmin and vmax are set.""" | |||
"""Return whether vim and max are both set""" |
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.
"""Return whether vim and max are both set""" | |
"""Return whether vim and max are both set.""" |
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.
Thanks for the very helpful suggestions!
Co-authored-by: Zihao Yang zihaoyng@gmail.com
Thanks @stevezhang1999 ! |
Co-authored-by: Zihao Yang zihaoyng@gmail.com
PR summary
The original description is not easy to understand for us (without playing with the API) so we tried to make it more clear and added some examples. Also we added documentation for methods that are not documented - we found some description about the methods issue tracker's threads!
PR checklist