gsplot.color.colormap#

Functions

get_cmap([cmap, N, cmap_data, normalize, ...])

Generates a colormap array using the specified parameters.

get_cmap(cmap='viridis', N=10, cmap_data=None, normalize=True, reverse=False)[source]#

Generates a colormap array using the specified parameters.

This function provides a convenient interface to create and customize colormaps using Matplotlib’s colormap utilities. Parameters can be passed directly or via a Colormap class.

Parameters:
  • cmap (str, optional) – The name of the Matplotlib colormap to use (default is “viridis”).

  • N (int or None, optional) – The number of evenly spaced values to generate for the colormap data. If None, cmap_data must be provided (default is 10).

  • cmap_data (array-like or None, optional) – Custom colormap data to use. If specified, N must be None (default is None).

  • normalize (bool, optional) – Whether to normalize the colormap data to the range [0, 1] (default is True).

  • reverse (bool, optional) – Whether to reverse the colormap data (default is False).

Notes

This function utilizes the ParamsGetter to retrieve bound parameters and the CreateClassParams class to handle the merging of default, configuration, and passed parameters.

Returns:

The generated colormap array as an RGBA numpy array.

Return type:

numpy.ndarray

Raises:

ValueError – If both N and cmap_data are provided simultaneously.

Examples

>>> import gsplot as gs
>>> colormap_array = gs.get_cmap(cmap="plasma", N=5, normalize=True, reverse=True)
>>> print(colormap_array)
[[0.940015  0.975158  0.131326  1.      ]
 [0.647257  0.107541  0.508936  1.      ]
 [0.20803   0.05997   0.481219  1.      ]
 [0.069447  0.037392  0.283268  1.      ]
 [0.050383  0.029803  0.527975  1.      ]]