Skip to content
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

Merged
merged 3 commits into from
Sep 28, 2023

Conversation

stevezhang1999
Copy link
Contributor

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

Co-authored-by: Zihao Yang zihaoyng@gmail.com
Copy link
Member

@jklymak jklymak left a 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.

lib/matplotlib/colors.py Outdated Show resolved Hide resolved
lib/matplotlib/colors.py Outdated Show resolved Hide resolved
Co-authored-by: Zihao Yang zihaoyng@gmail.com
@stevezhang1999
Copy link
Contributor Author

Updated with the suggestions.

Copy link
Member

@timhoffm timhoffm left a 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.

Comment on lines 1218 to 1220
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*.
Copy link
Member

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, ...)

Suggested change
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*.

Comment on lines 1226 to 1233
# [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]
Copy link
Member

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

Suggested change
# [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.]

@@ -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"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Return whether vim and max are both set"""
"""Return whether vim and max are both set."""

Copy link
Contributor Author

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
@timhoffm timhoffm added this to the v3.9.0 milestone Sep 28, 2023
@timhoffm timhoffm merged commit 93cab2e into matplotlib:main Sep 28, 2023
42 checks passed
@timhoffm
Copy link
Member

Thanks @stevezhang1999 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants