[docs]classCmap(AbstractMatWrap):def__init__(self,symmetric:bool=False,**kwargs):""" Customizes the Matplotlib colormap and its normalization. This object wraps the following Matplotlib methods: - colors.Linear: https://matplotlib.org/3.3.2/tutorials/colors/colormaps.html - colors.LogNorm: https://matplotlib.org/3.3.2/tutorials/colors/colormapnorms.html - colors.SymLogNorm: https://matplotlib.org/3.3.2/api/_as_gen/matplotlib.colors.SymLogNorm.html The cmap that is created is passed into various Matplotlib methods, most notably imshow: - https://matplotlib.org/3.3.2/api/_as_gen/matplotlib.pyplot.imshow.html Parameters ---------- symmetric If True, the colormap normalization (e.g. `vmin` and `vmax`) span the same absolute values producing a symmetric color bar. """super().__init__(**kwargs)self._symmetric=symmetricself.symmetric_value=Nonedefsymmetric_cmap_from(self,symmetric_value=None):cmap=copy.copy(self)cmap._symmetric=Truecmap.symmetric_value=symmetric_valuereturncmap
[docs]defnorm_from(self,array:np.ndarray,use_log10:bool=False)->object:""" Returns the `Normalization` object which scales of the colormap. If vmin / vmax are not manually input by the user, the minimum / maximum values of the data being plotted are used. Parameters ---------- array The array of data which is to be plotted. """vmin=self.vmin_from(array=array,use_log10=use_log10)vmax=self.vmax_from(array=array,use_log10=use_log10)ifself._symmetric:ifvmin<0.0andvmax>0.0:ifself.symmetric_valueisNone:ifabs(vmin)>abs(vmax):vmax=abs(vmin)else:vmin=-vmaxelse:vmin=-self.symmetric_valuevmax=self.symmetric_valueifisinstance(self.config_dict["norm"],colors.Normalize):returnself.config_dict["norm"]ifself.config_dict["norm"]in"log"oruse_log10:returncolors.LogNorm(vmin=vmin,vmax=vmax)elifself.config_dict["norm"]in"linear":returncolors.Normalize(vmin=vmin,vmax=vmax)elifself.config_dict["norm"]in"symmetric_log":returncolors.SymLogNorm(vmin=vmin,vmax=vmax,linthresh=self.config_dict["linthresh"],linscale=self.config_dict["linscale"],)elifself.config_dict["norm"]in"diverge":returncolors.TwoSlopeNorm(vmin=vmin,vcenter=0,vmax=vmax)raiseexc.PlottingException("The normalization (norm) supplied to the plotter is not a valid string must be ""{linear, log, symmetric_log}")