Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
New data → color pipeline#28658
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
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
1e52ba89e5620db3f5260edbe127fc9973e596daec21a5a645755d1ba6fe9e8dbe8cc39ac27397dd31ad1ecfe95c685f36676a31fc3cad60269ace9336a9baFile 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
The Colorizer class, ColorizerShim, and ColorableArtist which replaces the old ScalarMappable.
- 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 |
|---|---|---|
| @@ -13,6 +13,7 @@ | ||
| import matplotlib as mpl | ||
| from . import _api, cbook | ||
| from .cm import Colorizer | ||
| from .path import Path | ||
| from .transforms import (BboxBase, Bbox, IdentityTransform, Transform, TransformedBbox, | ||
| TransformedPatchPath, TransformedPath) | ||
| @@ -1392,6 +1393,80 @@ def set_mouseover(self, mouseover): | ||
| mouseover = property(get_mouseover, set_mouseover) # backcompat. | ||
| class ColorizingArtist(Artist): | ||
| def __init__(self, norm=None, cmap=None): | ||
| """ | ||
| Parameters | ||
| ---------- | ||
| norm : `colors.Normalize` (or subclass thereof) or str or `cm.Colorizer` or None | ||
| The normalizing object which scales data, typically into the | ||
| interval ``[0, 1]``. | ||
| If a `str`, a `colors.Normalize` subclass is dynamically generated based | ||
| on the scale with the corresponding name. | ||
| If `cm.Colorizer`, the norm an colormap on the `cm.Colorizer` will be used | ||
| ||
| If *None*, *norm* defaults to a *colors.Normalize* object which | ||
| initializes its scaling based on the first data processed. | ||
| cmap : str or `~matplotlib.colors.Colormap` | ||
| The colormap used to map normalized data values to RGBA colors. | ||
| """ | ||
| Artist.__init__(self) | ||
| self._A = None | ||
| if isinstance(norm, Colorizer): | ||
| self.colorizer = norm | ||
| if cmap: | ||
| raise ValueError("Providing a `cm.Colorizer` as the norm while " | ||
| "at the same time as a `cmap` is not supported..") | ||
| else: | ||
| self.colorizer = Colorizer(cmap, norm) | ||
| self._id_colorizer = self.colorizer.callbacks.connect('changed', self.changed) | ||
| self.callbacks = cbook.CallbackRegistry(signals=["changed"]) | ||
| def set_array(self, A): | ||
| """ | ||
| Set the value array from array-like *A*. | ||
| Parameters | ||
| ---------- | ||
| A : array-like or None | ||
| The values that are mapped to colors. | ||
| The base class `.VectorMappable` does not make any assumptions on | ||
| the dimensionality and shape of the value array *A*. | ||
trygvrad marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| """ | ||
| if A is None: | ||
| self._A = None | ||
| return | ||
| A = cbook.safe_masked_invalid(A, copy=True) | ||
| if not np.can_cast(A.dtype, float, "same_kind"): | ||
| raise TypeError(f"Image data of dtype {A.dtype} cannot be " | ||
| "converted to float") | ||
| self._A = A | ||
| if not self.norm.scaled(): | ||
timhoffm marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page.
| ||
| self.colorizer.autoscale_None(A) | ||
| def get_array(self): | ||
| """ | ||
| Return the array of values, that are mapped to colors. | ||
| The base class `.VectorMappable` does not make any assumptions on | ||
| the dimensionality and shape of the array. | ||
| """ | ||
| return self._A | ||
| def changed(self): | ||
| """ | ||
| Call this whenever the mappable is changed to notify all the | ||
| callbackSM listeners to the 'changed' signal. | ||
| """ | ||
| self.callbacks.process('changed') | ||
| self.stale = True | ||
| def _get_tightbbox_for_layout_only(obj, *args, **kwargs): | ||
| """ | ||
| Matplotlib's `.Axes.get_tightbbox` and `.Axis.get_tightbbox` support a | ||
Uh oh!
There was an error while loading.Please reload this page.