xoa.color.CmapAdapter
- class xoa.color.CmapAdapter(cmap, specs=None)[source]
Adapt a given colormap to data
- Parameters:
cmap – The colormap to adapt
specs (str, None) –
Transformation specifications or None.
When a string, it must have the format
"<type><value>"
, where type is"piv"
or"cyc"
, and value is convertible to a float.If type is
"piv"
, that colormap is expected typically to be diverging, and is cropped usingcrop_cmap()
, after min and max value are set withset_vlim()
.If type is
"cyc"
, min is set to 0 and max tovalue
, and the colormap is expected to be circular, like"cmo.phase"
.
Example
In [1]: cma = CmapAdapter('cmo.balance', 'piv0') In [2]: data = np.arange(100).reshape(10, 10) - 20 In [3]: cma.set_vlim(data.min(), data.max()) Out[3]: (-20, 79) In [4]: plt.contourf(data, **cma.get_dict()); In [5]: plt.colorbar();
Methods
get_cmap
()Get the adapted colormap
get_dict
()The specs for plots as a dict whose keys are cmap, vmin and vmax
set_vlim
(vmin, vmax)Set the min and max data value for scaling