-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Make _get_rgba_face actually always return a RGBA. #9911
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
Conversation
56c8925
to
2d962a6
Compare
lib/matplotlib/lines.py
Outdated
@@ -793,16 +793,15 @@ def draw(self, renderer): | |||
rgbaFace = self._get_rgba_face() | |||
rgbaFaceAlt = self._get_rgba_face(alt=True) | |||
edgecolor = self.get_markeredgecolor() | |||
if (isinstance(edgecolor, six.string_types) | |||
and edgecolor.lower() == 'none'): | |||
if cbook._str_equal(edgecolor, "none"): |
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.
Original code has edgecolor.lower()
, I do not see any normalization in set_markeredgecolor
/get_markeredgecolor
. Did I miss something?
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.
fixed
else: | ||
rgbaFace = mcolors.to_rgba(facecolor, self._alpha) | ||
return rgbaFace | ||
return mcolors.to_rgba(self._get_markerfacecolor(alt=alt), self._alpha) |
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.
The same as above
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.
to_rgba already handles the lowercasing (https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/colors.py#L146).
8743dce
to
85191a0
Compare
lib/matplotlib/cbook/__init__.py
Outdated
|
||
This helper solely exists to handle the case where *obj* is a numpy array. | ||
""" | ||
return isinstance(obj, six.string_types) and obj.lower() == s |
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 this not call lower
?
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.
duh...
85191a0
to
038306a
Compare
038306a
to
47e25e9
Compare
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.
Apart from the docstrings I flagged, it looks fine.
lib/matplotlib/cbook/__init__.py
Outdated
def _str_equal(obj, s): | ||
"""Return whether *obj* is a string equal to string *s*. | ||
|
||
This helper solely exists to handle the case where *obj* is a numpy array. |
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 find this confusing. How does it handle that case? It returns False, so that np.array('abc')
is not equal to 'abc'. Where is this needed? And why is it only the numpy array case that needs to be handled? I can imagine there might be other places in the code where this might be useful because 'obj' might be None, or a number, or...
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.
if obj is a number or None or etc., then, obj == s
will return False just fine. The problem with ndarrays is that np.array(...) == s
will return an array, which cannot be used in a boolean switch context.
The fact that np.array("abc")
will compare unequal to "abc" did not change with this PR, we were previously already using isinstance().
Perhaps the docstring can be clarified to
Return whether obj is a string equal to string s.
This helper solely exists to handle the case where obj is a numpy array, because in such cases, a naive
obj == s
would yield an array, which cannot be used in a boolean context.
How does that sound? Feel free to propose further edits.
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.
That's good, thank you.
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.
edited accordingly (both instances)
_get_rgba_face is an internal function that is only use to set the graphicscontext's foreground color (in Line2D.draw); it is always effectively called as `gc.set_foreground(line._get_rgba_face(...), isRGBA=True)`. So it makes sense to have it actually always return a RGBA quadruplet, including when the color is "none" (in which case `mcolors.to_rgba` returns (0, 0, 0, 0) regardless of alpha, which works just fine). This removes the need for third party graphicscontexts to handle non-RGBA-quadruplets (specifically, None) even when set_foreground is actually called with isRGBA=True.
47e25e9
to
ee13342
Compare
_get_rgba_face is an internal function that is only use to set the
graphicscontext's foreground color (in Line2D.draw); it is always
effectively called as
gc.set_foreground(line._get_rgba_face(...), isRGBA=True)
. So it makes sense to have it actually always return aRGBA quadruplet, including when the color is "none" (in which case
mcolors.to_rgba
returns (0, 0, 0, 0) regardless of alpha, which worksjust fine).
This removes the need for third party graphicscontexts to handle
non-RGBA-quadruplets (specifically, None) even when set_foreground is
actually called with isRGBA=True.
PR Summary
PR Checklist