Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
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 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.
Multivar imshow#30597
Changes from1 commit
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
…how, pcolor, pcolormesh, and Collection
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -6150,6 +6150,7 @@ 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*. | ||||||||||||||||||||||||
| - (v, M, N): if coupled with a cmap that supports v scalars | ||||||||||||||||||||||||
| - (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. | ||||||||||||||||||||||||
| @@ -6159,15 +6160,16 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None, | ||||||||||||||||||||||||
| Out-of-range RGB(A) values are clipped. | ||||||||||||||||||||||||
| %(multi_cmap_doc)s | ||||||||||||||||||||||||
| This parameter is ignored if *X* is RGB(A). | ||||||||||||||||||||||||
| %(multi_norm_doc)s | ||||||||||||||||||||||||
| This parameter is ignored if *X* is RGB(A). | ||||||||||||||||||||||||
| %(multi_vmin_vmax_doc)s | ||||||||||||||||||||||||
| This parameter is ignored if *X* is RGB(A). | ||||||||||||||||||||||||
| @@ -6246,6 +6248,9 @@ 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. | ||||||||||||||||||||||||
| Only 'data' is available when using `~matplotlib.colors.BivarColormap` | ||||||||||||||||||||||||
| or `~matplotlib.colors.MultivarColormap` | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||
| @@ -6351,6 +6356,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: | ||||||||||||||||||||||||
| @@ -6506,9 +6512,10 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None, | ||||||||||||||||||||||||
| Parameters | ||||||||||||||||||||||||
| ---------- | ||||||||||||||||||||||||
| C : 2Dor 3Darray-like | ||||||||||||||||||||||||
| The color-mapped values. Color-mapping is controlled by *cmap*, | ||||||||||||||||||||||||
| *norm*, *vmin*, and *vmax*. 3D arrays are supported only if the | ||||||||||||||||||||||||
| cmap supports v channels, where v is the size along the first axis. | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| X, Y : array-like, optional | ||||||||||||||||||||||||
| The coordinates of the corners of quadrilaterals of a pcolormesh:: | ||||||||||||||||||||||||
| @@ -6555,11 +6562,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. | ||||||||||||||||||||||||
| %(multi_cmap_doc)s | ||||||||||||||||||||||||
| %(multi_norm_doc)s | ||||||||||||||||||||||||
| %(multi_vmin_vmax_doc)s | ||||||||||||||||||||||||
| %(colorizer_doc)s | ||||||||||||||||||||||||
| @@ -6634,8 +6641,17 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None, | ||||||||||||||||||||||||
| if shading is None: | ||||||||||||||||||||||||
| shading = mpl.rcParams['pcolor.shading'] | ||||||||||||||||||||||||
| shading = shading.lower() | ||||||||||||||||||||||||
| if colorizer is None: | ||||||||||||||||||||||||
| cmap = mcolorizer._ensure_cmap(cmap, accept_multivariate=True) | ||||||||||||||||||||||||
| C = mcolorizer._ensure_multivariate_data(args[-1], cmap.n_variates) | ||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||
| C = mcolorizer._ensure_multivariate_data(args[-1], | ||||||||||||||||||||||||
| colorizer.cmap.n_variates) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| ifcolorizerisNone: | |
| cmap=mcolorizer._ensure_cmap(cmap,accept_multivariate=True) | |
| C=mcolorizer._ensure_multivariate_data(args[-1],cmap.n_variates) | |
| else: | |
| C=mcolorizer._ensure_multivariate_data(args[-1], | |
| colorizer.cmap.n_variates) | |
| ifcolorizerisNone: | |
| cmap=mcolorizer._ensure_cmap(cmap,accept_multivariate=True) | |
| colorizer= | |
| C=mcolorizer._ensure_multivariate_data(args[-1], | |
| colorizer.cmap.n_variates) |
is there a reason to not instantiate the colorizer here?
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 believe it was designed this way to ensure error handling was done in the same way as previously, but I was able to rework it to a cleaner state by doing
mcolorizer.ColorizingArtist._check_exclusionary_keywords(colorizer, vmin=vmin, vmax=vmax, norm=norm, cmap=cmap)before the creation of the QuadMesh rather than
collection._check_exclusionary_keywords(colorizer, vmin=vmin, vmax=vmax)after.
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.
potentially turn into a helper function if it repeats?
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.
The following lines are repeated for pcolor and pcolormesh:
mcolorizer.ColorizingArtist._check_exclusionary_keywords(colorizer,vmin=vmin,vmax=vmax,norm=norm,cmap=cmap)ifcolorizerisNone:colorizer=mcolorizer.Colorizer(cmap=cmap,norm=norm)C=mcolorizer._ensure_multivariate_data(args[-1],colorizer.cmap.n_variates)
We could make this a helper function :)
If so, should it be part of the Axes class? and do you have a suggestion for a name?
EDIT: this is after modifying it in accordance with one of your comments above :)
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,7 +12,13 @@ from matplotlib.collections import ( | ||
| QuadMesh, | ||
| ) | ||
| from matplotlib.colorizer import Colorizer | ||
| from matplotlib.colors import ( | ||
| Colormap, | ||
| BivarColormap, | ||
| MultivarColormap, | ||
| Norm, | ||
| Normalize, | ||
| ) | ||
| from matplotlib.container import ( | ||
| BarContainer, PieContainer, ErrorbarContainer, StemContainer) | ||
| from matplotlib.contour import ContourSet, QuadContourSet | ||
| @@ -500,14 +506,14 @@ class Axes(_AxesBase): | ||
| def imshow( | ||
| self, | ||
| X: ArrayLike | PIL.Image.Image, | ||
| cmap: str | Colormap |BivarColormap | MultivarColormap |None = ..., | ||
| norm: str |Norm | None = ..., | ||
| *, | ||
| aspect: Literal["equal", "auto"] | float | None = ..., | ||
| interpolation: str | None = ..., | ||
| alpha: float | ArrayLike | None = ..., | ||
| vmin: float |tuple[float] |None = ..., | ||
| vmax: float |tuple[float] |None = ..., | ||
trygvrad marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| colorizer: Colorizer | None = ..., | ||
| origin: Literal["upper", "lower"] | None = ..., | ||
| extent: tuple[float, float, float, float] | None = ..., | ||
| @@ -524,10 +530,10 @@ class Axes(_AxesBase): | ||
| *args: ArrayLike, | ||
| shading: Literal["flat", "nearest", "auto"] | None = ..., | ||
| alpha: float | None = ..., | ||
| norm: str |Norm | None = ..., | ||
| cmap: str | Colormap |BivarColormap | MultivarColormap |None = ..., | ||
| vmin: float |tuple[float] |None = ..., | ||
| vmax: float |tuple[float] |None = ..., | ||
trygvrad marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| colorizer: Colorizer | None = ..., | ||
| data=..., | ||
| **kwargs | ||
| @@ -536,10 +542,10 @@ class Axes(_AxesBase): | ||
| self, | ||
| *args: ArrayLike, | ||
| alpha: float | None = ..., | ||
| norm: str |Norm | None = ..., | ||
| cmap: str | Colormap |BivarColormap | MultivarColormap |None = ..., | ||
| vmin: float |tuple[float] |None = ..., | ||
| vmax: float |tuple[float] |None = ..., | ||
trygvrad marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| colorizer: Colorizer | None = ..., | ||
| shading: Literal["flat", "nearest", "gouraud", "auto"] | None = ..., | ||
| antialiased: bool = ..., | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,13 +9,13 @@ class Colorizer: | ||
| callbacks: cbook.CallbackRegistry | ||
| def __init__( | ||
| self, | ||
| cmap: str | colors.Colormap |colors.BivarColormap | colors.MultivarColormap |None = ..., | ||
| norm: str | colors.Norm | None = ..., | ||
| ) -> None: ... | ||
| @property | ||
| def norm(self) -> colors.Norm: ... | ||
| @norm.setter | ||
| def norm(self, norm: colors.Norm | str |tuple[str] |None) -> None: ... | ||
| ||
| def to_rgba( | ||
| self, | ||
| x: np.ndarray, | ||
| @@ -26,28 +26,28 @@ class Colorizer: | ||
| def autoscale(self, A: ArrayLike) -> None: ... | ||
| def autoscale_None(self, A: ArrayLike) -> None: ... | ||
| @property | ||
| def cmap(self) -> colors.Colormap | colors.BivarColormap | colors.MultivarColormap: ... | ||
| @cmap.setter | ||
| def cmap(self, cmap: colors.Colormap |colors.BivarColormap | colors.MultivarColormap |str | None) -> None: ... | ||
| def get_clim(self) -> tuple[float, float]: ... | ||
| def set_clim(self, vmin: float | tuple[float, float] | None = ..., vmax: float | None = ...) -> None: ... | ||
| def changed(self) -> None: ... | ||
| @property | ||
| def vmin(self) -> float |tuple[float] |None: ... | ||
| @vmin.setter | ||
| def vmin(self, value: float |tuple[float] |None) -> None: ... | ||
| @property | ||
| def vmax(self) -> float |tuple[float] |None: ... | ||
| @vmax.setter | ||
| def vmax(self, value: float |tuple[float] |None) -> None: ... | ||
| @property | ||
| def clip(self) -> bool | tuple[bool, ...]: ... | ||
| @clip.setter | ||
| def clip(self, value:ArrayLike |bool) -> None: ... | ||
| class _ColorizerInterface: | ||
| cmap: colors.Colormap | colors.BivarColormap | colors.MultivarColormap | ||
| colorbar: colorbar.Colorbar | None | ||
| callbacks: cbook.CallbackRegistry | ||
| def to_rgba( | ||
| @@ -60,8 +60,8 @@ class _ColorizerInterface: | ||
| def get_clim(self) -> tuple[float, float]: ... | ||
| def set_clim(self, vmin: float | tuple[float, float] | None = ..., vmax: float | None = ...) -> None: ... | ||
| def get_alpha(self) -> float | None: ... | ||
| def get_cmap(self) -> colors.Colormap | colors.BivarColormap | colors.MultivarColormap: ... | ||
| def set_cmap(self, cmap: str | colors.Colormap | colors.BivarColormap | colors.MultivarColormap) -> None: ... | ||
| @property | ||
| def norm(self) -> colors.Norm: ... | ||
| @norm.setter | ||
| @@ -75,7 +75,7 @@ class _ScalarMappable(_ColorizerInterface): | ||
| def __init__( | ||
| self, | ||
| norm: colors.Norm | None = ..., | ||
| cmap: str | colors.Colormap |colors.BivarColormap | colors.MultivarColormap |None = ..., | ||
| *, | ||
| colorizer: Colorizer | None = ..., | ||
| **kwargs | ||
Uh oh!
There was an error while loading.Please reload this page.