-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Multivar imshow #30597
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
Multivar imshow #30597
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4a2cfc9
expose multivariate plotting functionality to top level functions ims…
trygvrad ca83ad3
updates from code review
trygvrad 02016b5
Apply suggestions from code review
trygvrad ddcfe37
improved consistency of return types for better typing
trygvrad fce7799
implementing feedback from story645
trygvrad 5393cba
doc fix for _ColorizerInterface.get_clim()
trygvrad b8caed7
update based on feedback from @timhoffm
trygvrad fdb3725
Apply suggestions from code review
trygvrad d49ef95
multivar imshow additional test
trygvrad b701032
updates based on feedback from @timhoffm
trygvrad c7988f4
updated docstring for multivariate imshow/pcolor/pcolormesh
trygvrad fa6c921
another update to docstring for multivariate imshow/pcolor/pcolormesh
trygvrad c62fa5a
Apply suggestion from @timhoffm
timhoffm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6238,6 +6238,11 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None, | |
| - (M, N): an image with scalar data. The values are mapped to | ||
| colors using normalization and a colormap. See parameters *norm*, | ||
| *cmap*, *vmin*, *vmax*. | ||
| - a (K, M, N) scalar array or a structured (M, N) array with K fields. | ||
| The K channels are mapped to colors using a `.MultiNorm` and a | ||
| `.BivarColormap` (K=2) or K-component `.MultivarColormap`. | ||
| This input option is only available when a `.BivarColormap` or | ||
| `.MultivarColormap` is provided to the *cmap* keyword argument. | ||
| - (M, N, 3): an image with RGB values (0-1 float or 0-255 int). | ||
| - (M, N, 4): an image with RGBA values (0-1 float or 0-255 int), | ||
| i.e. including transparency. | ||
|
|
@@ -6247,15 +6252,16 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None, | |
|
|
||
| Out-of-range RGB(A) values are clipped. | ||
|
|
||
| %(cmap_doc)s | ||
|
|
||
| This parameter is ignored if *X* is RGB(A). | ||
| %(multi_cmap_doc)s | ||
|
|
||
| %(norm_doc)s | ||
| Scalar colormaps are ignored if *X* is RGB(A). | ||
|
|
||
| %(multi_norm_doc)s | ||
|
|
||
| This parameter is ignored if *X* is RGB(A). | ||
|
|
||
| %(vmin_vmax_doc)s | ||
| %(multi_vmin_vmax_doc)s | ||
|
|
||
| This parameter is ignored if *X* is RGB(A). | ||
|
|
||
|
|
@@ -6334,6 +6340,10 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None, | |
| See :doc:`/gallery/images_contours_and_fields/image_antialiasing` for | ||
| a discussion of image antialiasing. | ||
|
|
||
| When using a `~matplotlib.colors.BivarColormap` or | ||
| `~matplotlib.colors.MultivarColormap`, 'data' is the only valid | ||
| interpolation_stage. | ||
|
|
||
| alpha : float or array-like, optional | ||
| The alpha blending value, between 0 (transparent) and 1 (opaque). | ||
| If *alpha* is an array, the alpha blending values are applied pixel | ||
|
|
@@ -6439,6 +6449,7 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None, | |
| if aspect is not None: | ||
| self.set_aspect(aspect) | ||
|
|
||
| X = mcolorizer._ensure_multivariate_data(X, im.norm.n_components) | ||
| im.set_data(X) | ||
| im.set_alpha(alpha) | ||
| if im.get_clip_path() is None: | ||
|
|
@@ -6594,9 +6605,23 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None, | |
|
|
||
| Parameters | ||
| ---------- | ||
| C : 2D array-like | ||
| The color-mapped values. Color-mapping is controlled by *cmap*, | ||
| *norm*, *vmin*, and *vmax*. | ||
| C : 2D or 3D array-like | ||
| The mesh data. Supported array shapes are: | ||
|
|
||
| - (M, N) or M*N: a mesh with scalar data. The values are mapped to | ||
| colors using normalization and a colormap. See parameters *norm*, | ||
| *cmap*, *vmin*, *vmax*. | ||
| - a (K, M, N) scalar array or a structured (M, N) array with K fields. | ||
| The K channels are mapped to colors using a `.MultiNorm` and a | ||
| `.BivarColormap` (K=2) or K-component `.MultivarColormap`. | ||
| This input option is only available when a `.BivarColormap` or | ||
| `.MultivarColormap` is provided to the *cmap* keyword argument. | ||
| - (M, N, 3): an image with RGB values (0-1 float or 0-255 int). | ||
| - (M, N, 4): an image with RGBA values (0-1 float or 0-255 int), | ||
| i.e. including transparency. | ||
|
|
||
| The first two dimensions (M, N) define the rows and columns of | ||
| the mesh data. | ||
|
|
||
| X, Y : array-like, optional | ||
| The coordinates of the corners of quadrilaterals of a pcolormesh:: | ||
|
|
@@ -6639,11 +6664,11 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None, | |
| See :doc:`/gallery/images_contours_and_fields/pcolormesh_grids` | ||
| for more description. | ||
|
|
||
| %(cmap_doc)s | ||
| %(multi_cmap_doc)s | ||
|
|
||
| %(norm_doc)s | ||
| %(multi_norm_doc)s | ||
|
|
||
| %(vmin_vmax_doc)s | ||
| %(multi_vmin_vmax_doc)s | ||
|
|
||
| %(colorizer_doc)s | ||
|
|
||
|
|
@@ -6718,8 +6743,19 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None, | |
| if shading is None: | ||
| shading = mpl.rcParams['pcolor.shading'] | ||
| shading = shading.lower() | ||
| X, Y, C, shading = self._pcolorargs('pcolor', *args, shading=shading, | ||
| kwargs=kwargs) | ||
|
|
||
| mcolorizer.ColorizingArtist._check_exclusionary_keywords(colorizer, | ||
| vmin=vmin, vmax=vmax, | ||
| norm=norm, cmap=cmap) | ||
| if colorizer is None: | ||
| colorizer = mcolorizer.Colorizer(cmap=cmap, norm=norm) | ||
|
|
||
| C = mcolorizer._ensure_multivariate_data(args[-1], | ||
| colorizer.cmap.n_variates) | ||
|
Comment on lines
+6753
to
+6754
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel
Good naming is hard and I propose to do this as a follow-up as this is internal and has been here before the PR. |
||
|
|
||
| X, Y, C, shading = self._pcolorargs('pcolor', *args[:-1], C, | ||
| shading=shading, kwargs=kwargs) | ||
|
|
||
| linewidths = (0.25,) | ||
| if 'linewidth' in kwargs: | ||
| kwargs['linewidths'] = kwargs.pop('linewidth') | ||
|
|
@@ -6754,9 +6790,7 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None, | |
| coords = stack([X, Y], axis=-1) | ||
|
|
||
| collection = mcoll.PolyQuadMesh( | ||
| coords, array=C, cmap=cmap, norm=norm, colorizer=colorizer, | ||
| alpha=alpha, **kwargs) | ||
| collection._check_exclusionary_keywords(colorizer, vmin=vmin, vmax=vmax) | ||
| coords, array=C, colorizer=colorizer, alpha=alpha, **kwargs) | ||
| collection._scale_norm(norm, vmin, vmax) | ||
|
|
||
| coords = coords.reshape(-1, 2) # flatten the grid structure; keep x, y | ||
|
|
@@ -6794,6 +6828,11 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None, | |
| - (M, N) or M*N: a mesh with scalar data. The values are mapped to | ||
| colors using normalization and a colormap. See parameters *norm*, | ||
| *cmap*, *vmin*, *vmax*. | ||
| - a (K, M, N) scalar array or a structured (M, N) array with K fields. | ||
| The K channels are mapped to colors using a `.MultiNorm` and a | ||
| `.BivarColormap` (K=2) or K-component `.MultivarColormap`. | ||
| This input option is only available when a `.BivarColormap` or | ||
| `.MultivarColormap` is provided to the *cmap* keyword argument. | ||
| - (M, N, 3): an image with RGB values (0-1 float or 0-255 int). | ||
| - (M, N, 4): an image with RGBA values (0-1 float or 0-255 int), | ||
| i.e. including transparency. | ||
|
|
@@ -6828,11 +6867,11 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None, | |
| expanded as needed into the appropriate 2D arrays, making a | ||
| rectangular grid. | ||
|
|
||
| %(cmap_doc)s | ||
| %(multi_cmap_doc)s | ||
|
|
||
| %(norm_doc)s | ||
| %(multi_norm_doc)s | ||
|
|
||
| %(vmin_vmax_doc)s | ||
| %(multi_vmin_vmax_doc)s | ||
|
|
||
| %(colorizer_doc)s | ||
|
|
||
|
|
@@ -6956,16 +6995,24 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None, | |
| shading = mpl._val_or_rc(shading, 'pcolor.shading').lower() | ||
| kwargs.setdefault('edgecolors', 'none') | ||
|
|
||
| X, Y, C, shading = self._pcolorargs('pcolormesh', *args, | ||
| mcolorizer.ColorizingArtist._check_exclusionary_keywords(colorizer, | ||
| vmin=vmin, vmax=vmax, | ||
| norm=norm, cmap=cmap) | ||
| if colorizer is None: | ||
| colorizer = mcolorizer.Colorizer(cmap=cmap, norm=norm) | ||
|
|
||
|
story645 marked this conversation as resolved.
|
||
| C = mcolorizer._ensure_multivariate_data(args[-1], | ||
| colorizer.cmap.n_variates) | ||
|
|
||
| X, Y, C, shading = self._pcolorargs('pcolormesh', *args[:-1], C, | ||
| shading=shading, kwargs=kwargs) | ||
| coords = np.stack([X, Y], axis=-1) | ||
|
|
||
| kwargs.setdefault('snap', mpl.rcParams['pcolormesh.snap']) | ||
|
|
||
| collection = mcoll.QuadMesh( | ||
| coords, antialiased=antialiased, shading=shading, | ||
| array=C, cmap=cmap, norm=norm, colorizer=colorizer, alpha=alpha, **kwargs) | ||
| collection._check_exclusionary_keywords(colorizer, vmin=vmin, vmax=vmax) | ||
| array=C, colorizer=colorizer, alpha=alpha, **kwargs) | ||
| collection._scale_norm(norm, vmin, vmax) | ||
|
|
||
| coords = coords.reshape(-1, 2) # flatten the grid structure; keep x, y | ||
|
|
@@ -8911,6 +8958,9 @@ def matshow(self, Z, **kwargs): | |
|
|
||
| """ | ||
| Z = np.asanyarray(Z) | ||
| if Z.ndim != 2: | ||
| if Z.ndim != 3 or Z.shape[2] not in (1, 3, 4): | ||
| raise TypeError(f"Invalid shape {Z.shape} for image data") | ||
| kw = {'origin': 'upper', | ||
| 'interpolation': 'nearest', | ||
| 'aspect': 'equal', # (already the imshow default) | ||
|
|
||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.