-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
2-D array RGB and RGBA values not understood in plt.plot() #18423
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
A couple of suggestions:
|
I am currently trying to create a test. The issue is as follows: The error is produced only when plt.show() is executed. However, it seems that plt.show() never gets executed in any of the existing tests. How would I check for the error when not using plt.show() ? |
|
Thank you, it is working great. Currently I am testing for 3*, 4*, 1D-color-array on plot() and scatter() functions. Which other cases do you suppose should be included in the test? I was thinking about hist() for example. |
Using https://matplotlib.org/3.3.0/api/testing_api.html#matplotlib.testing.decorators.check_figures_equal may be very useful here so you can pass the ndim==1 and ndim==2 versions of the same color to the same function and then assert that they generate identical output. |
@danuo overall this looks good - be sure to ping us for review if it gets buried... |
I have all the tests fully working with the @check_figures_equal()
def test_2dcolor_plot(fig_test, fig_ref):
color = np.array([0.1,0.2,0.3])
fig_test.subplots().plot([1,2],[1,2],c=color.reshape((-1)))
fig_ref.subplots().plot([1,2],[1,2], c=color.reshape((1,-1))) |
Probably worth also adding a test in I have a slight concern that we are going to find a different case where projecting down here is going to give the wrong answer, but apparently we don't have any test that exercises this code path at all... |
4dbcb89
to
05f1359
Compare
I am not sure what you mean by this. I have implemented all of your other proposals |
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 @danuo!
@danuo this needs two reviews, so be sure to ping if you don't get a second one. @tacaswell may or may not clarify what he meant 😉 |
Putting a test in assert mcolors.to_rbga([r, g, b]) == mcolors.to_rgba([[r, g, b]]) or similar to directly test the change (rather than implicitly via the plot / scatter behavior). |
05f1359
to
33d2069
Compare
@tacaswell Done, I have implemented such a test in test_colors. Again, the test fails with current matplotlib version and succeeds with this fix. Can you make a second review? |
d63fb4f
to
aaac772
Compare
This will need a rebase due to the conflicts. |
with 1d color arrays against one with 2d color arrays. They should be identical if 2d arrays are read correctly. + Rebase with master + Change .reshape((-1)) to .reshape(-1)
colors.to_rgba() + Rebase with master + Change .reshape((-1)) to .reshape(-1)
75389ad
to
369ba34
Compare
remove white space
Thanks @danuo! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again. |
closes #18411
PR Summary
This fixes the problem discussed in the linked issue in the most simple and general way.
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
andpydocstyle<4
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).