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. n
| 36 | |
| 37 | |
| 38 | class Colorizer: |
| 39 | """ |
| 40 | Data to color pipeline. |
| 41 | |
| 42 | This pipeline is accessible via `.Colorizer.to_rgba` and executed via |
| 43 | the `.Colorizer.norm` and `.Colorizer.cmap` attributes. |
| 44 | |
| 45 | Parameters |
| 46 | ---------- |
| 47 | cmap: colorbar.Colorbar or str or None, default: None |
| 48 | The colormap used to color data. |
| 49 | |
| 50 | norm: colors.Normalize or str or None, default: None |
| 51 | The normalization used to normalize the data |
| 52 | """ |
| 53 | def __init__(self, cmap=None, norm=None): |
| 54 | |
| 55 | self._cmap = None |
| 56 | self._set_cmap(cmap) |
| 57 | |
| 58 | self._id_norm = None |
| 59 | self._norm = None |
| 60 | self.norm = norm |
| 61 | |
| 62 | self.callbacks = cbook.CallbackRegistry(signals=["changed"]) |
| 63 | self.colorbar = None |
| 64 | |
| 65 | def _scale_norm(self, norm, vmin, vmax, A): |
| 66 | """ |
| 67 | Helper for initial scaling. |
| 68 | |
| 69 | Used by public functions that create a ScalarMappable and support |
| 70 | parameters *vmin*, *vmax* and *norm*. This makes sure that a *norm* |
| 71 | will take precedence over *vmin*, *vmax*. |
| 72 | |
| 73 | Note that this method does not set the norm. |
| 74 | """ |
| 75 | if vmin is not None or vmax is not None: |
| 76 | self.set_clim(vmin, vmax) |
| 77 | if isinstance(norm, colors.Normalize): |
| 78 | raise ValueError( |
| 79 | "Passing a Normalize instance simultaneously with " |
| 80 | "vmin/vmax is not supported. Please pass vmin/vmax " |
| 81 | "as arguments to the norm object when creating it") |
| 82 | |
| 83 | # always resolve the autoscaling so we have concrete limits |
| 84 | # rather than deferring to draw time. |
| 85 | self.autoscale_None(A) |
| 86 | |
| 87 | @property |
| 88 | def norm(self): |
| 89 | return self._norm |
| 90 | |
| 91 | @norm.setter |
| 92 | def norm(self, norm): |
| 93 | norm = _ensure_norm(norm, n_components=self.cmap.n_variates) |
| 94 | if norm is self.norm: |
| 95 | # We aren't updating anything |
no outgoing calls
no test coverage detected
searching dependent graphs…