diagnostic.visualizations.create_custom_cmap#

create_custom_cmap(hex_color1: str, hex_color2: str, num_colors: int)[source]#

Create a custom colormap that transitions between two given hex colors and generates a specified number of colors.

Parameters:
  • hex_color1 (str) – The starting color of the colormap in hex format (e.g., ‘#FF0000’ for red).

  • hex_color2 (str) – The ending color of the colormap in hex format (e.g., ‘#0000FF’ for blue).

  • num_colors (int) – The number of colors to generate in the colormap, including both the start and end colors.

Returns:

  • cmap (matplotlib.colors.LinearSegmentedColormap) – A colormap that can be used in plotting functions to visualize data with a color gradient from hex_color1 to hex_color2.

  • colors (numpy.ndarray) – An array of the RGB values for each of the colors in the generated colormap.

Example

>>> cmap, colors = create_custom_cmap("#FF0000", "#0000FF", 10)
>>> plt.imshow([colors], aspect='auto')
>>> plt.show()