Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Multivariate plotting in imshow, pcolor and pcolormesh#29221
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Also: this does not (yet) include changes to the docstrings, i.e. the following will need to change:
to include a line like
|
I updated the docstrings, so now this PR should be ready for review. There is an error with the docs on circleci, but I haven't found a link between the error and the changes made in this PR, so I believe it to be unrelated. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
trygvrad commentedFeb 8, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@story645 also: this will need a squash-merge |
e30e7e6
tof936378
CompareUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
# pass scalar data | ||
# and already formatted data | ||
return data | ||
elif data.dtype in [np.complex64, np.complex128]: |
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.
Option 1 please.
Uh oh!
There was an error while loading.Please reload this page.
if A.ndim == 3 and A.shape[-1] == 1: | ||
A = A.squeeze(-1) # If just (M, N, 1), assume scalar and apply colormap. | ||
if not (A.ndim == 2 or A.ndim == 3 and A.shape[-1] in [3, 4]): | ||
if A.ndim == 3 and A.shape[0] == 2: |
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 verify, these are here as a hint to the user to use multi-variate color maps and data that would have failed before would still fail now?
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.
Yes, that is the intention
raise TypeError(f"Image data of dtype {A.dtype} cannot be " | ||
f"converted to float") | ||
else: | ||
for key in A.dtype.fields: |
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 think this fails to catchn_input >1
+ non-float-like + non-structured data?
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.
This might be true.
I'm trying to think of a data type that can not be cast to float and is not structured in order to test this
If you try something with data type object, it depends a bit on the shape, all the cases I have tried have been caught:
fig,ax=plt.subplots()im=np.empty((5,5),dtype='object')ax.imshow(im,cmap='BiOrangeBlue')>ValueError:Invaliddataentryformutlivariatedata.Thedatamustcontaincomplexnumbers,orhaveafirstdimension2,orbeofadtypewith2fieldsim=np.empty((2,5,5),dtype='object')ax.imshow(im,cmap='BiOrangeBlue')>TypeError:Imagedataofdtype [('f0','O'), ('f1','O')]cannotbeconvertedtoasequenceoffloats
Where the first error originates incolorizer._ensure_multivariate_data()
Do you have some idea of other tests I should run, or do we want to have specific tests for_normalize_image_array()
?
Uh oh!
There was an error while loading.Please reload this page.
lib/matplotlib/image.py Outdated
""" | ||
Check validity of image-like input *A* and normalize it to a format suitable for | ||
Image subclasses. | ||
""" | ||
A = mcolorizer._ensure_multivariate_data(n_input, A) |
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.
minor thing. bit jarring that sometimes the API inf(n_input, A)
and othertimesf(A, n_input)
. I think we should preferf(A, n_input)
everywhere for internal consistency and no-API change on existing functions (like the one we are in now).
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.
This is a good comment :) I will try to address it soon
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 changed the call signature ofcolorizer._ensure_multivariate_data(...)
tocolorizer._ensure_multivariate_data(A, n_input)
I looked to see if there were any other functions with a similar signature which should be flipped, but I did not find any in my quick search.
63e789a
to7fc99b5
CompareIf you've got the bandwidth,@greglucas can you give this a look (skim) since you've been working on colormapping? |
@greglucas It would be great to know if/when you will have time to look at this :) |
trygvrad commentedMar 27, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@story645@tacaswell would you two be willing to finish your review of this? EDIT: my apologies@story645 I didn't see you had just assigned this when I wrote my comment :) |
@anntzer asked if the more cleanup/refactor/not directly necessary for implementation parts of this PR could be spun off into a different set and if this PR could get rebased to clean up the commit history. |
trygvrad commentedApr 1, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@anntzer I'll see what I can do.
I'll also see if there are some misc changes that can be a separate PR between 1 and 2. |
I guess it doesn't really matter, because we know the end result thanks to this PR anyways. |
If an image is shown, and the user hovers over the image, the value at that coordinate should be displayed. The number formating is handled by colorizer.Colorizer._format_cursor_data_override(). This is now updated to also handle the case where a MultiNorm is used (i.e. a bivariat or multivariate colormap), in which case multiple values are displayed.
The previous version of this test passed for numpy 1.x but not for 2.x. This should pass for both
Co-authored-by: Thomas A Caswell <tcaswell@gmail.com>
changed from colorizer._ensure_multivariate_data(n_input, A)to colorizer._ensure_multivariate_data(A, n_input)
PR summary
This PR continues the work of#28658 and#28454, aiming toclose#14168.
Featuresincluded in this PR:
MultiNorm
class. This is a subclass ofcolors.Normalize
and holdsn_variate
norms.MultiNorm
together withBivarColormap
andMultivarColormap
to the plotting functionsaxes.imshow(...)
,axes.pcolor
, and `axes.pcolormesh(...)Featuresnot included in this PR:
fig.colorbar(...)
. I will make a draft for this, but I may need help with regards to the layout engine.fig.colorbar(...)
solution for bivariate/multivariate colormaps.axes.imshow(...)
included here only acceptsinterpolation_stage=='rgba'
, and notinterpolation_stage=='data'
.PR checklist
fig.colorbar(...)
equivalent for multivariate colormaps.