Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: Allow RGB(A) arrays for pcolormesh #24619

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
merged 2 commits into from
Dec 5, 2022

Conversation

greglucas
Copy link
Contributor

@greglucas greglucas commented Dec 4, 2022

PR Summary

Allow a user to set the array values to explicit colors with RGB(A) values in the 3rd dimension. We already use mcolors.to_rgba() to set the facecolors and that will do the RGB(A) handling for us as long as we use 3D arrays. i.e. we can't handle (h*w, 4) flattened arrays with colors.

closes #4277
closes #24418
closes #22236 (separate commit to handle pcolorfast in case we want this as a separate PR)

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@greglucas greglucas added this to the v3.7.0 milestone Dec 4, 2022
Allow a user to set the array values to explicit colors with RGB(A)
values in the 3rd dimension.
@tacaswell
Copy link
Member

I'm honestly surprised that this was mostly removing / modifying input validation code.

@greglucas
Copy link
Contributor Author

I'm honestly surprised that this was mostly removing / modifying input validation code.

This is really helped out by moving the QuadMesh coordinates and array towards accepting 2D inputs and this being an extension of that.

@ksunden ksunden merged commit d46c27a into matplotlib:main Dec 5, 2022
C = C.ravel()
# convert to one dimensional array, except for 3D RGB(A) arrays
if C.ndim != 3:
C = C.ravel()
Copy link
Member

Choose a reason for hiding this comment

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

Why do 3-D arrays not need to be flattened at all?

Copy link
Member

Choose a reason for hiding this comment

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

or conversely, why are we flattening 2-D arrays?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I am not a fan of the flattening either... Allowing 2-D arrays is pretty new (only the last couple of releases), so everyone always used to have to flatten their arrays before getting/setting arrays. Unfortunately, that is baked into a few of our tests as expecting to pass a 2-D array in, and then calling mesh = plt.pcolormesh(z2d); mesh.get_array() == z2d.ravel(). I don't think we should be messing with people's arrays if they pass them in as 2D, but that may be too controversial to change at this point too...

Copy link
Contributor Author

@greglucas greglucas Dec 5, 2022

Choose a reason for hiding this comment

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

Why do 3-D arrays not need to be flattened at all?

Specifically for 3-D, we can not flatten them because the image RGB(A) color handling code will only handle the 3-D shapes of (M, N, [3 or 4])

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.

[ENH]: rgp or rgba option for pyplot pcolormesh and/or pcolor [Bug]: integer colours for pcolorfast / quadmesh RGB not supported in pcolormesh
4 participants