ColorHandler#

class zeroheliumkit.src.plotting.ColorHandler(colors: dict)[source]#

Bases: object

A class to handle color/layer adjustments for plotting. The ‘colors’ attribute of the Base class is set to an instance of ColorHandler(), which holds and modifies the colors/layers mapping and order for plotting.

Parameters:
  • colors (dict) – dictionary mapping of layer names to (color, transparancy) tuples.

  • color_cycle (list) – list of colors to cycle through when no color is provided.

Methods

add_color(layer, color, alpha)

Adds a color to the colors list when a layer is added.

bring_forward(layer)

bring_to_front(layer)

change_color(lname, new_color)

Updates the color of a layer in the colors attribute.

move_layer(layer[, move_by])

Moves a layer by a given number of indices in the color dictionary.

print()

remove_color(color)

Removes a color when a layer is removed.

rename_color(old_color, new_color)

Renames a color when a layer is renamed.

send_backward(layer)

send_to_back(layer)

update_colors(layers)

Updates colors when layers are imported from external files.

Attributes

colors

Dictionary mapping of layer names to [color, transparancy] tuples.

color_cycle

List of colors to cycle through when no color is provided.

is_empty

Checks if the colors attribute is empty.

colors#

Dictionary mapping of layer names to [color, transparancy] tuples.

color_cycle#

List of colors to cycle through when no color is provided.

property is_empty: bool#

Checks if the colors attribute is empty.

Returns:

True if the colors attribute is empty, False otherwise.

Return type:

bool

change_color(lname: str, new_color: tuple | list) ColorHandler[source]#

Updates the color of a layer in the colors attribute.

Args:

lname (str): The name of the layer to update. new_color (str): Color code, alpha value, or a tuple of both to update the layer with.

Returns:

  • Updated instance (self) of the class with the specified layer’s color changed.

    Raises:

    ValueError: If the new_color parameter is not a tuple, string, or float. ValueError: If the given color is anot a valid color code.

update_colors(layers: list) ColorHandler[source]#

Updates colors when layers are imported from external files.

Args:

layers (list): list of layers to update the colors list in accordance with.

Returns:

  • Updated instance (self) with the udpated colors attribute.

add_color(layer: str, color: str | None, alpha: float | None) ColorHandler[source]#

Adds a color to the colors list when a layer is added.

Parameters:
  • layer (str) – layer name to add to the list.

  • color_info (tuple(str, int)) – color and transparancy to map to the layer.

rename_color(old_color: str, new_color: str) ColorHandler[source]#

Renames a color when a layer is renamed.

Parameters:
  • old_color (str) – old color name

  • new_color (str) – new color name

remove_color(color: str) ColorHandler[source]#

Removes a color when a layer is removed.

Parameters:

color (str) – color to remove in the colors attribute.

move_layer(layer: str, move_by: int = 1)[source]#

Moves a layer by a given number of indices in the color dictionary.

Parameters:
  • layer (str) – the name of the layer to move.

  • move_by (int) – the number of indices to move the color by.