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
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
18 commits Select commitHold shift + click to select a range
1e52ba8 Colorizer class
trygvrad9e5620d Creation of colorizer.py
trygvradb3f5260 updated ColorizingArtist.__init__
trygvradedbe127 simplify to_rgba() by extracting the part relating to RGBA data
trygvradfc9973e updated class hierarchy for Colorizer
trygvrad596daec colorizer keyword on plotting functions with typing
trygvrad21a5a64 changes to keyword parameter ordering
trygvrad5755d1b adjustments based on code review
trygvrada6fe9e8 MNT: adjust inheritance so isinstance(..., cm.ScalarMappable) works
tacaswelldbe8cc3 updated docs with colorizer changes
trygvrad9ac2739 updates to colorizer pipeline based on feedback from @QuLogic
trygvrad7dd31ad DOC: fix unrelated xref issues
tacaswell1ecfe95 DOC: add multivariate colormaps to the docs
tacaswellc685f36 DOC: fix colorizer related xrefs
tacaswell676a31f DOC: auto-generate ScalarMappable in conf.py
tacaswellc3cad60 Corrections based on feedback from @QuLogic
trygvrad269ace9 MNT: Touch up rebase to use 'register' for docstring interpolations
ksunden336a9ba fix missing refererence linenos
ksundenFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Corrections based on feedback from@QuLogic
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
68 changes: 39 additions & 29 deletionslib/matplotlib/colorizer.py
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 |
|---|---|---|
| @@ -11,35 +11,44 @@ | ||
| :doc:`/gallery/color/colormap_reference` for a list of builtin colormaps. | ||
| :ref:`colormap-manipulation` for examples of how to make colormaps. | ||
| :ref:`colormaps` for an in-depth discussion of choosing colormaps. | ||
| :ref:`colormapnorms` for more details about data normalization. | ||
| """ | ||
| import functools | ||
| import numpy as np | ||
| from numpy import ma | ||
| from matplotlib import _api, colors, cbook, scale, artist | ||
| import matplotlib as mpl | ||
| mpl._docstring.interpd.update( | ||
| colorizer_doc="""\ | ||
| colorizer : `~matplotlib.colorizer.Colorizer` or None, default: None | ||
| The Colorizer object used to map color to data. If None, a Colorizer | ||
| object is createdfrom a *norm* and *cmap*.""", | ||
| ) | ||
| class Colorizer: | ||
| """ | ||
| Data to color pipeline. | ||
| This pipeline is accessible via `.Colorizer.to_rgba` and executed via | ||
| the `.Colorizer.norm` and `.Colorizer.cmap` attributes. | ||
| Parameters | ||
| ---------- | ||
| cmap: colorbar.Colorbar or str or None, default: None | ||
| The colormap used to color data. | ||
| norm: colors.Normalize or str or None, default: None | ||
| The normalization used to normalize the data | ||
| """ | ||
| def __init__(self, cmap=None, norm=None): | ||
QuLogic marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| @@ -225,8 +234,7 @@ def _set_cmap(self, cmap): | ||
| # bury import to avoid circular imports | ||
| from matplotlib import cm | ||
| in_init = self._cmap is None | ||
| self._cmap = cm._ensure_cmap(cmap) | ||
| if not in_init: | ||
| self.changed() # Things are not set up properly yet. | ||
| @@ -280,15 +288,15 @@ def changed(self): | ||
| @property | ||
| def vmin(self): | ||
| return self.get_clim()[0] | ||
| @vmin.setter | ||
| def vmin(self, vmin): | ||
| self.set_clim(vmin=vmin) | ||
| @property | ||
| def vmax(self): | ||
| return self.get_clim()[1] | ||
| @vmax.setter | ||
| def vmax(self, vmax): | ||
| @@ -439,6 +447,9 @@ def autoscale_None(self): | ||
| @property | ||
| def colorbar(self): | ||
| """ | ||
| The last colorbar associated with this object. May be None | ||
| """ | ||
| return self._colorizer.colorbar | ||
| @colorbar.setter | ||
| @@ -485,10 +496,8 @@ class _ScalarMappable(_ColorizerInterface): | ||
| """ | ||
| A mixin class to map one or multiple sets of scalar data to RGBA. | ||
| The ScalarMappable applies data normalization before returning RGBA colors from | ||
| the given `~matplotlib.colors.Colormap`. | ||
| """ | ||
| # _ScalarMappable exists for compatibility with | ||
| @@ -582,7 +591,7 @@ def _check_exclusionary_keywords(colorizer, **kwargs): | ||
| @staticmethod | ||
| def _get_colorizer(cmap, norm, colorizer): | ||
| if isinstance(colorizer, Colorizer): | ||
| _ScalarMappable._check_exclusionary_keywords( | ||
| Colorizer, cmap=cmap, norm=norm | ||
| ) | ||
| @@ -620,15 +629,20 @@ def _get_colorizer(cmap, norm, colorizer): | ||
| class ColorizingArtist(_ScalarMappable, artist.Artist): | ||
QuLogic marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| """ | ||
| Base class for artists that make map data to color using a `.colorizer.Colorizer`. | ||
| The `.colorizer.Colorizer` applies data normalization before | ||
| returning RGBA colors from a `~matplotlib.colors.Colormap`. | ||
| """ | ||
| def __init__(self, colorizer, **kwargs): | ||
| """ | ||
| Parameters | ||
| ---------- | ||
| colorizer : `.colorizer.Colorizer` | ||
| """ | ||
| _api.check_isinstance(Colorizer, colorizer=colorizer) | ||
| super().__init__(colorizer=colorizer, **kwargs) | ||
| @property | ||
| @@ -637,18 +651,14 @@ def colorizer(self): | ||
| @colorizer.setter | ||
| def colorizer(self, cl): | ||
| _api.check_isinstance(Colorizer, colorizer=cl) | ||
| self._colorizer.callbacks.disconnect(self._id_colorizer) | ||
| self._colorizer = cl | ||
| self._id_colorizer = cl.callbacks.connect('changed', self.changed) | ||
| def _set_colorizer_check_keywords(self, colorizer, **kwargs): | ||
| """ | ||
| Raises a ValueError if any kwarg is not None while colorizer is not None. | ||
| """ | ||
| self._check_exclusionary_keywords(colorizer, **kwargs) | ||
| self.colorizer = colorizer | ||
4 changes: 2 additions & 2 deletionslib/matplotlib/contour.py
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
13 changes: 13 additions & 0 deletionslib/matplotlib/tests/test_colors.py
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
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.