amep.plot.linear_mappable#
- amep.plot.linear_mappable(cmap: str | Colormap | None, vmin: float, vmax: float, cscale: str = 'lin') _ScalarMappable#
Generate a scalar mappable colormap.
Used to color lines according to some value v between vmin and vmax with color=sm.to_rgba(v).
- Parameters:
cmap (str or mpl.colors.Colormap or None) – Colormap object or name of the colormap. If None, the default colormap is used as specified in the used style sheet.
vmin (float) – Minimum value.
vmax (float) – Maximum value.
cscale (str, optional) – Color scale. Use ‘lin’ for a linear scale and ‘log’ for a logarithmic scale. The default is ‘lin’.
- Returns:
sm – Object that maps a float to an rgba value.
- Return type:
mpl.cm.ScalarMappable
Examples
>>> import amep >>> import numpy as np >>> x = np.linspace(0,10,100) >>> z = np.linspace(0,2,20) >>> sm = amep.plot.linear_mappable('viridis', 0, 2) >>> fig, axs = amep.plot.new() >>> for i in range(len(z)): ... axs.plot(x, x+i, c=sm.to_rgba(z[i]), marker='' ... ) >>> cax = amep.plot.add_colorbar(fig, axs, sm, label=r'$z$') >>> axs.set_xlabel(r'$x$') >>> axs.set_ylabel(r'$y$') >>> fig.savefig('./figures/plot/plot-linear_mappable.png') >>>