pynetdesign.visualization.utils.generate_colorscale#
- pynetdesign.visualization.utils.generate_colorscale(cmap, ncolors)[source]#
Generate a colorscale from a colormap and number of colors.
- Parameters:
- cmap
mcolors.Colormap A colormap instance from matplotlib.colors to be used for generating the colorscale.
- ncolors
int The number of colors to generate in the colorscale. Must be a positive integer.
- cmap
- Returns:
- colorscale
list A list of colors in the format [[position, ‘rgb(r, g, b)’], …] where position is a float between 0 and 1 representing the color position, and ‘rgb(r, g, b)’ is the color at that position in RGB format.
- colorscale
- Raises:
- ValueError
If ncolors is less than 2 or if cmap is not an instance of mcolors.Colormap.
Examples
>>> from matplotlib import cm >>> generate_colorscale(cm.viridis, 5) [[0.0, 'rgb(0.267004, 0.004874, 0.329415)'], [0.25, 'rgb(0.229739, 0.322361, 0.545706)'], [0.5, 'rgb(0.127568, 0.566949, 0.550556)'], [0.75, 'rgb(0.369214, 0.788888, 0.382914)'], [1.0, 'rgb(0.993248, 0.906157, 0.143936)']] [[0.0, 'rgb(68, 1, 84)'], [0.25, 'rgb(58, 82, 139)'], [0.5, 'rgb(32, 144, 140)'], [0.75, 'rgb(94, 201, 97)'], [1.0, 'rgb(253, 231, 36)']]