neuralib.plot.colormap

class neuralib.plot.colormap.DiscreteColorMapper[source]

map color to iterable object

Example of a ``dict`` palette

>>> palette = {3: ('#3182bd', '#6baed6', '#9ecae1'),
...            5: ('#a1d99b', '#c7e9c0', '#756bb1', '#9e9ac8', '#bcbddc')}
>>> cmapper = DiscreteColorMapper(palette, 5)
>>> x = ['1', '2', '3']
>>> color_list = [cmapper[i] for i in x]

Example of a mpl ``str`` palette

>>> cmapper = DiscreteColorMapper('viridis', 20)
>>> regions = ['rsc', 'vis', 'hpc']
>>> color_list = [cmapper[r] for r in regions]
__init__(palette, number)[source]
Parameters:
  • palette (dict[int, tuple[str, ...]] | str) – A custom dictionary color palette or a Matplotlib colormap name

  • number (int) – Number of colors to cycle through in the palette or colormap

neuralib.plot.colormap.get_customized_cmap(name, value, numbers, endpoint=True)[source]

Generate gradient color map array. N = number of color

Parameters:
  • name (str) – name of cmap

  • value (tuple[float, float]) – value range, could be 0-1

  • numbers (int) – N

  • endpoint (bool) – If cyclic colormap, then used False

Returns:

RGBA. Array[float, [N, 4]]

Return type:

ndarray

neuralib.plot.colormap.insert_colorbar(ax, im, **kwargs)[source]

Insert colormap

Parameters:
  • ax (Axes) – Axes

  • im (_ScalarMappable) – ScalarMappable

  • kwargs – Additional args pass to ax.figure.colorbar

Returns:

Return type:

Colorbar

neuralib.plot.colormap.insert_cyclic_colorbar(ax, im, *, num_colors=12, num_labels=4, width=0.6, inner_diameter=0.6, vmin=None, vmax=None)[source]

Insert cyclic colormap in inset_axes

Parameters:
  • ax (Axes) – Axes

  • im (_ScalarMappable) – ScalarMappable

  • num_colors (int) – Number of color in the cyclic colorbar

  • num_labels (int) – Number of labels in the cyclic colorbar

  • width (float) – Width of the each color

  • inner_diameter (float) – The size of the inner circle

  • vmin (float | None) – Min value of the colormap, equal to vmax in cyclic data

  • vmax (float | None) – Max value of the colormap, equal to vmin in cyclic data

Return type:

None