Skip to content

API

Make a custom colormap from a list of colors

References

[1] https://matplotlib.org/stable/users/explain/colors/colormap-manipulation.html

drawColorBar

drawColorBar(cmap: Union[mpl.colors.ListedColormap, mpl.colors.LinearSegmentedColormap, str]) -> mpl.figure.Figure

Draw a colorbar from the colormap

Parameters:

Name Type Description Default
cmap

A Listed colormap, a linear segmented colormap or the name of a registered colormap

required

Returns:

Type Description
Figure

A matplotlib Figure object

drawColorCircle

drawColorCircle(cmap: Union[mpl.colors.ListedColormap, mpl.colors.LinearSegmentedColormap, str], n: int = 24, area: int = 200) -> mpl.axes.Axes

Draw a color circle from the colormap

Parameters:

Name Type Description Default
cmap

A Listed colormap, a linear segmented colormap or the name of a registered colormap

required
n

Number of colors to display in the color circle (set n=256 for a continuous circle)

24
area

Size of the circles to draw

200

Returns:

Type Description
Axes

A matplotlib Axes object

get_cmap

get_cmap(name: Optional[str] = None, colormap_filename: str = DEFAULT_COLORMAP) -> dict[str, tuple[mpl.colors.ListedColormap, mpl.colors.LinearSegmentedColormap, str]]

Return the selected LinearSegmentedColormap or a dictionary of all colormaps registered in colormap_filename

Parameters:

Name Type Description Default
name

Name of the colormap

None
colormap_filename

Path to a JSON file encoding a dictionary of colors which define custom colormaps

DEFAULT_COLORMAP

Returns:

Type Description
dict[str, tuple[ListedColormap, LinearSegmentedColormap, str]]

A dictionary of colormap names and the corresponding listed and linear segmented colormaps

get_colors

get_colors(cmap: Union[mpl.colors.ListedColormap, mpl.colors.LinearSegmentedColormap, str], n: int, scramble: bool = False) -> np.ndarray

Extract n colors from a colormap

Parameters:

Name Type Description Default
cmap

A Listed colormap, a linear segmented colormap or the name of a registered colormap

required
n

Number of colors to extract from the colormap

required
scramble bool

Whether to scramble the color

False

Returns:

Type Description
ndarray

A numpy array of colors

list_cmaps

list_cmaps() -> list[str]

List all available colormaps

Returns:

Type Description
list[str]

A list of colormap names

load_colors

load_colors(filename: str = DEFAULT_COLORMAP)

Load rgba colors from a json file

Parameters:

Name Type Description Default
filename

JSON filename of user defined colormaps (defaults to the in-build colormaps of the package)

DEFAULT_COLORMAP

make_colormap

make_colormap(colors: np.ndarray, name: str = 'newcolormap') -> tuple[mpl.colors.ListedColormap, mpl.colors.LinearSegmentedColormap, str]

Build a listed and a linear segmented colormap from a list of colors

Parameters:

Name Type Description Default
colors

A numpy array of RGB colors

required
name

The name of the new colormap

'newcolormap'

Returns:

Type Description
tuple[ListedColormap, LinearSegmentedColormap, str]

A matplotlib LinearSegmented or Listed colormap

naturalcolors

naturalcolors() -> tuple[mpl.colors.ListedColormap, mpl.colors.LinearSegmentedColormap, str]

Wrapper for naturalcolors map

Returns:

Type Description
tuple[ListedColormap, LinearSegmentedColormap, str]

A listed and linear segmented colormaps

set_ticksStyle

set_ticksStyle(x_size: float = 4, y_size: float = 4, x_dir: str = 'in', y_dir: str = 'in')

Ticks settings for plotting

Parameters:

Name Type Description Default
x_size

length of x-ticks

4
y_size

length of y-ticks

4
x_dir

inward or outward facing x-ticks ("in" or "out")

'in'
y_dir

inward or outward facing y-ticks ("in" or "out")

'in'