-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Raise warning if both c and facecolors are used in scatter plot (... and related improvements in the test suite). #29130
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
…he future we may implement c as edgecolors in that case or cause plot to fail.
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.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code of Conduct.
Would you like me to push another commit and PR that removes the offending extra line and whitespace (flake8 fail) or edit the PR? |
I see the other failures are because of two tests failing: one because my warning was triggered for test_legend_pathcollection_labelcolor_markfacecolor_cmap
And the other because another warning was triggered.
I just raised issue #29131 about that one. |
To pass flake8 formatting check
lib/matplotlib/axes/_axes.py
Outdated
"You passed both c and facecolor/facecolors for the markers. " | ||
"Matplotlib is ignoring the facecolor " | ||
"in favor of what you specified in c. " |
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.
Slightly more concise:
"You passed both c and facecolor/facecolors for the markers. " | |
"Matplotlib is ignoring the facecolor " | |
"in favor of what you specified in c. " | |
"Passing both c and facecolor/facecolors for the markers " | |
"is ambiguous. facecolor is ignored in in favor of c. " |
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.
Thank you for reviewing the comment. Your change is more concise, and I understand the argument that matplotlib developers consider passing both as ambiguous.
However, a user intentionally passing both will likely not understand why it is ambiguous. They probably assumed incorrectly, as the issue's Original Poster did, that c defines both a face color and edge color and that just like adding edge color works, the face color can also be overwritten.
Yes, you've don this correctly: Please update this PR and do not create new ones on the same topic. You can choose whether to add additional commits or force-push a new version. |
…otlib into issue24404_addwarning
I tried out the test code that was failing fig, ax = plt.subplots()
facecolors = mpl.cm.viridis(np.random.rand(10))
ax.scatter(
np.arange(10),
np.arange(10),
label='#1',
c=np.arange(10),
facecolor=facecolors
) As I suspected, facecolors doesn't do anything in that case, so my addition justifiably raises the warning. This, of course, alters the outcome from the assertion's previous expectation. fig, ax = plt.subplots()
ax.scatter(
np.arange(10),
np.arange(10),
label='#1',
c=np.arange(10)
) which produces the indentical plot as before (I tested it with .canvas.tostring_rgb()). |
That failing test was added in Commit 66ec3a0 . fig, ax = plt.subplots()
facecolors = mpl.cm.viridis(np.random.rand(10))
ax.scatter(
np.arange(10),
np.arange(10),
label='#1',
facecolor=facecolors
)
leg = ax.legend(labelcolor='markerfacecolor')
for text, color in zip(leg.get_texts(), ['k']):
assert mpl.colors.same_color(text.get_color(), color) This will let the random color assignment shine through, but it won't raise a warning. The only problem would be if a visual compare test were done with its old output. |
I want to mention that I am working on an alternative branch where I add an ec (edge colors) arg to .scatter() that parallels c's functionality and would come before the current 'edgecolors' arg (which I bump to kwargs). This would make it explicit that c should not be used for specifically setting edge colors and return intuitive, symmetrical functionality to .scatter(). (timhoffm: accidental edit reverted) |
@timhoffm, your edit to my comment above is full of good points. |
Sorry for editing your comment. I intended to click "quote reply" but accidentally hit the wrong button 🐑. I've reverted the edit. For reference, here is my comment: I'm sceptical on this. |
You should look into #28658 and #28428, which generalize the colormapping concept. The case of separate edgecolor mapping is not explicitly contained, but fits into that context. |
Codecov doesn't like that in my test I wrote:
I think it considers the output of that function as untested. But I was just following the lead of three tests above it, which it is also complaining about. Should I change my test, or ignore it? The other failing check is build time taking over an hour (including the test suite, I think). I'm not sure that is because of something I did, though. |
lib/matplotlib/tests/test_axes.py
Outdated
def get_next_color(): | ||
return 'blue' # currently unused | ||
|
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.
Let's not move the get_next_color()
functions out of the tests. This produces an indirection (harder to read) and implicit coupling of the tests. There's also value in the "currently unused" comment in here.
Compared to this, the repetition of two lines is clearly the lesser evil.
Even better would be a local function
def get_next_color():
raise AssertionError("Color cycle should not be accessed")
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 have no problem rolling back those commits.
But what do you want to do about the fact that CodeCov raises an "Uncovered" flag by every incidence of return 'blue'
? It even failed my code because I had added another incidence of that: (https://github.com/matplotlib/matplotlib/pull/29130/checks?check_run_id=33222717934)
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.
CodeCov does not strictly need to pass, but we have it for information only.
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.
Rolled back.
611a9dc
to
38c092a
Compare
lib/matplotlib/tests/test_axes.py
Outdated
@@ -3027,7 +3027,7 @@ def get_next_color(): | |||
]) | |||
def test_parse_scatter_color_args_edgecolors(kwargs, expected_edgecolors): | |||
def get_next_color(): |
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.
def get_next_color(): | |
def get_next_color(): # pragma no cover |
Pretty sure it has to go next to the function declaration because you're telling coverage to ignore this whole block
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.
You're right. That was my instinct as well, but I saw @jefromyers did it next to the return statement
matplotlib/lib/matplotlib/tests/test_axes.py
Line 8298 in 04ce3e9
return 'blue' # pragma: no cover |
I just corrected it.
The AppVeyor check failed, but after reading the error logs, and doing the same workflow on my Mac, I believe it's a Windows problem unrelated to my change. |
…he future we may implement c as edgecolors in that case or cause plot to fail.
e6e49aa
to
a18364c
Compare
I rebased my branch but incidentally created duplicate commits on top. I should have used interactive rebase, sorry. |
Is there anything else I can do to improve my Pull Request? |
Co-authored-by: Tim Hoffmann <[email protected]>
Anything else? |
Thank you, @timhoffm |
Thanks @NGWi, sorry it took so long to follow up, hope to see more contributions from you! 🥳 |
Thanks 😀
…On Fri, Jan 3, 2025 at 9:36 AM hannah ***@***.***> wrote:
Thanks @NGWi <https://github.com/NGWi>, sorry it took so long to follow
up, hope to see more contributions from you! 🥳
—
Reply to this email directly, view it on GitHub
<#29130 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANEGD73HTFOXV3LFGJ4K4O32I2N55AVCNFSM6AAAAABRVFGIR6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNRZGMYTINJUGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
You didn't trigger a backport, if this milestone was intentional. |
Uch what's the command again? I think this should get back ported since it's just an error check, right? |
@meeseeksdev backport to v3.10.x |
…are used in scatter plot (... and related improvements in the test suite).
…130-on-v3.10.x Backport PR #29130 on branch v3.10.x (Raise warning if both c and facecolors are used in scatter plot (... and related improvements in the test suite).)
This is to fulfill @tacaswell's recommendation (at the PyData sprint I joined last week) that for a quick fix to close issue #24404, we raise a warning when such a script is attempted.
The complaint in that issue was: that if both c and facecolors args are specified for a plot's markers (specifically a scatterplot), then the facecolors arg is ignored, while a user might expect that facecolors would be used for the fill and the 'c' color would remain at the edges.
I have the code raise a warning in the style of others I saw in _axes.py :
"You passed both c and facecolor/facecolors for the markers. "
"Matplotlib is ignoring the facecolor "
"in favor of what you specified in c. "
"This behavior may change in the future."
I am hoping that in the future we can implement c as edgecolors in that case, and we are not forced at some point to cause the plot to fail.
PR checklist