Skip to content

plotynium.context

plotynium.context.Context

The Context holds all information shared to Mark objects and Legend object. These information are computed dimensions, options, scalers and labels.

Parameters:

Name Type Description Default

canvas_properties

CanvasProperties

Canvas properties (width, height and margin)

required

legend_properties

LegendProperties

Legend properties (width, height and margin)

required

x_options

XOptions

X axis options

required

y_options

YOptions

Y axis options

required

color_options

ColorOptions

Color options

required

style_options

StyleOptions

Style options

required

symbol_options

SymbolOptions

Symbol options

required

x_scale

Scaler

X scale from detroit

required

y_scale

Scaler

Y scale from detroit

required

x_label

str | None

X label

None

y_label

str | None

Y label

None
Source code in plotynium/context.py
def __init__(
    self,
    canvas_properties: CanvasProperties,
    legend_properties: LegendProperties,
    x_options: XOptions,
    y_options: YOptions,
    color_options: ColorOptions,
    style_options: StyleOptions,
    symbol_options: SymbolOptions,
    x_scale: Scaler,
    y_scale: Scaler,
    x_label: str | None = None,
    y_label: str | None = None,
):
    self._canvas_properties = canvas_properties
    self._legend_properties = legend_properties

    self._x_options = x_options
    self._y_options = y_options
    self._color_options = color_options
    self._style_options = style_options
    self._symbol_options = symbol_options

    self._color_mapping = []
    self._symbol_mapping = []

    self._x = x_scale
    self._y = y_scale

background property

background

Returns the background value.

Returns:

Type Description
str

Background value

canvas_translate property

canvas_translate

Returns the canvas translation value. For instance, "translate(15, 12)" and if x and y values of the translation equal zero, it returns None.

Returns:

Type Description
str | None

Translation value of the canvas

color property

color

Returns the color of the text.

Returns:

Type Description
str

Text color value

color_mapping property

color_mapping

Returns color mapping collected after the application of marks.

Returns:

Type Description
list[tuple[str, str]]

List of pairs (label, color)

color_scheme property

color_scheme

Returns the color scheme value.

Returns:

Type Description
ColorScheme

Color scheme value

font_family property

font_family

Returns the font family.

Returns:

Type Description
str

Font family value

font_size property

font_size

Returns the font size.

Returns:

Type Description
int

Font size value

height property

height

Returns height size of the canvas.

Returns:

Type Description
int

Height size of the canvas

labels property

labels

Returns the definition of user labels.

Returns:

Type Description
dict[int, str]

Dictionary where keys are indices of labels and values are label values

legend_properties property

legend_properties

Returns legend properties.

Returns:

Type Description
LegendProperties

Legend properties.

margin property

margin

Returns margin values of the canvas.

Returns:

Type Description
int

Margin values of the canvas

symbol_mapping property

symbol_mapping

Returns symbol mapping collected after the application of marks.

Returns:

Type Description
list[tuple[str, str]]

List of pairs (label, symbol path)

width property

width

Returns width size of the canvas.

Returns:

Type Description
int

Width size of the canvas

x property

x

Returns X scale.

Returns:

Type Description
Scaler

X scale

x_label property

x_label

Returns X label.

Returns:

Type Description
str | None

X label

y property

y

Returns Y scale.

Returns:

Type Description
Scaler

Y scale

y_label property

y_label

Returns Y label.

Returns:

Type Description
str | None

Y label

update_color_mapping

update_color_mapping(*color_mappings)

Sets the color mapping by prioritizing the longest color mapping list.

Parameters:

Name Type Description Default

color_mappings

tuple[list[tuple[str, str]]]

Several list of pairs (label, color)

()
Source code in plotynium/context.py
def update_color_mapping(self, *color_mappings: tuple[list[tuple[str, str]]]):
    """
    Sets the color mapping by prioritizing the longest color mapping list.

    Parameters
    ----------
    color_mappings : tuple[list[tuple[str, str]]]
        Several list of pairs (label, color)
    """
    color_mappings = [self._color_mapping] + list(color_mappings)
    self._color_mapping = max(color_mappings, key=len)

update_symbol_mapping

update_symbol_mapping(*symbol_mappings)

Sets the symbol mapping by prioritizing the longest symbol mapping list.

Parameters:

Name Type Description Default

symbol_mappings

tuple[list[tuple[str, str]]]

Several list of pairs (label, symbol path)

()
Source code in plotynium/context.py
def update_symbol_mapping(self, *symbol_mappings: tuple[list[tuple[str, str]]]):
    """
    Sets the symbol mapping by prioritizing the longest symbol mapping list.

    Parameters
    ----------
    symbol_mappings : tuple[list[tuple[str, str]]]
        Several list of pairs (label, symbol path)
    """
    symbol_mappings = [self._symbol_mapping] + list(symbol_mappings)
    self._symbol_mapping = max(symbol_mappings, key=len)