-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix is_color_like
for 2-tuple of strings and fix to_rgba
for (nth_color, alpha)
#28436
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
timhoffm
approved these changes
Jun 22, 2024
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.
Optionally add more color variants to the is_color_like test.
But if I do that I might find more bugs! 😆 This should work I think? In [6]: to_rgba(('C3', 0.5))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[6], line 1
----> 1 to_rgba(('C3', 0.5))
File ~/git_stuff/matplotlib/lib/matplotlib/colors.py:309, in to_rgba(c, alpha)
307 rgba = None
308 if rgba is None: # Suppress exception chaining of cache lookup failure.
--> 309 rgba = _to_rgba_no_colorcycle(c, alpha)
310 try:
311 _colors_full_map.cache[c, alpha] = rgba
File ~/git_stuff/matplotlib/lib/matplotlib/colors.py:391, in _to_rgba_no_colorcycle(c, alpha)
387 raise ValueError(
388 f"Invalid string grayscale value {orig_c!r}. "
389 f"Value must be within 0-1 range")
390 return c, c, c, alpha if alpha is not None else 1.
--> 391 raise ValueError(f"Invalid RGBA argument: {orig_c!r}")
392 # turn 2-D array into 1-D array
393 if isinstance(c, np.ndarray):
ValueError: Invalid RGBA argument: 'C3' |
and fix to_rgba for (nth_color, alpha)
is_color_like
for 2-tuple of stringsis_color_like
for 2-tuple of strings and fix to_rgba
for (nth_color, alpha)
timhoffm
approved these changes
Jun 22, 2024
story645
approved these changes
Jun 23, 2024
meeseeksmachine
pushed a commit
to meeseeksmachine/matplotlib
that referenced
this pull request
Jun 23, 2024
…ngs and fix `to_rgba` for `(nth_color, alpha)`
greglucas
pushed a commit
that referenced
this pull request
Jun 24, 2024
…x `to_rgba` for `(nth_color, alpha)` (#28438) Co-authored-by: hannah <[email protected]>
2 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR summary
Currently if we do
we get the unhelpful error shown in #28434. I couldn't find any existing tests for
is_color_like
so added a few. In the process of adding tests, found thatis also broken (see #28436 (comment)), so fixed that too.
Closes #28434, since this fixes the reported bug. There was a suggestion there about supporting color sequences in
plot
but it seems like that would be difficult to do. If we do want to discuss it further it might make sense to open a separate feature request issue.PR checklist