scistag.plotstag.plot.Plot

class Plot(target_size=None)[source]

Bases: object

Defines a single plot.

A plot defines an area within a Figure which can consist of one or multiple plots overlaying of each other using the :class:`PlotLayer`s provided such as line charts, scatter plots, images etc.

Parameters

target_size (Size2DTypes | None) – The target size in pixels

Methods

add_image

Adds an image layer

add_layer

Adds a layer to this plot

add_matplot

Adds a matplotlib figure as image layer to the plot

get_figure

Returns the plot's figure.

paint

Paints the plot and all of it's layers and subcomponents such as the legend.

render

Renders the plot's figure

set_figure

Links the plot to the figure which contains it

set_title

Sets the plot's title

update_layout

Updates the plot's layout to compute the plot's efficient size

update_margins

Updates the current layer offset :return:

Attributes

__dict__

__doc__

__module__

__weakref__

list of weak references to the object (if defined)

target_size

Desired target size in pixels

size

Plot's effective size in pixels (as far as defined)

layers

Single data visualization layers (the real plots)

border_width

Border width in pixels

border_margins

Border margin in pixels

border_color

Border color

margins

Margin around the main layers in pixels on each side (left, top, right, bottom)

layer_pos

Position at which the layers shall be plotted

layer_size

The layer size in pixels

_figure

Figure which contains this plot

column

Column in which the plot is displayed.

row

Row in which the plot is displayed.

index

Enumeration index of the plot.

title

The plot's title

title_height

The title's size in pixels

_title_font

Cached title font

title_spacing

Space above and below the title

title_color

The title's color

_paint_decoration(canvas)[source]

Paints the decoration such as border and title

Parameters

canvas – The target canvas

_repr_png_()[source]

Creates a PNG representation for Jupyter

Return type

bytes

Returns

The PNG data

add_image(image, size_ratio=None, bg_fill='cb')[source]

Adds an image layer

Parameters
  • image (Image | np.ndarray) – The image to plot

  • size_ratio (float | tuple[float, float] | None) –

    The size ratio from the image’s or matrix original size to effective pixels. This can be used to plot images in original size rather than being auto-scaled through the plot’s configuration.

    • 1.0 = keep the original size.

    • 0.5 = 50% of the original size

  • bg_fill (str | Color | None) –

    Defines the background which shall be used if the image is alpha-transparent. If a color is passed the whole background will be filled with given color.

    ”cb” (checkerboard) by default.

Return type

Plot

add_layer(layer)[source]

Adds a layer to this plot

Parameters

layer (PlotLayer) – The new layer

add_matplot(figure=None, size_ratio=None, **params)[source]

Adds a matplotlib figure as image layer to the plot

Parameters
  • figure (plt.Figure | None) – The figure to be added

  • size_ratio (float | None) – If set the plot will be scaled with given factor

  • params – The parameters to be passed to the figure if a new figure shall be created.

Returns

The Plot if a figure was passed (and so no further action is required).

Otherwise an MPLayerLock which shall be used the following way:

with my_plot.add_matplot() as plt:
    plt.title(...)
    plt.imshow(...)

get_figure()[source]

Returns the plot’s figure.

If no figure was assigned yet it will automatically create it

Returns

The figure

paint(canvas)[source]

Paints the plot and all of it’s layers and subcomponents such as the legend.

Parameters

canvas (Canvas) – The target canvas

render()[source]

Renders the plot’s figure

Return type

Image

Returns

The visualization of the plot as Image

set_figure(figure)[source]

Links the plot to the figure which contains it

Parameters

figure (Figure) – The figure

Return type

None

set_title(title)[source]

Sets the plot’s title

Parameters

title (str | None) – The plot’s title text. None do deactivate the title

Return type

Plot

Returns

The plot

update_layout()[source]

Updates the plot’s layout to compute the plot’s efficient size

update_margins()[source]

Updates the current layer offset :return:

_figure: Optional['Figure']

Figure which contains this plot

_title_font: Font | None

Cached title font

border_color

Border color

border_margins

Border margin in pixels

border_width

Border width in pixels

column

Column in which the plot is displayed. Auto-assigned by the figure

index

Enumeration index of the plot. Auto-assigned by the figure

layer_pos

Position at which the layers shall be plotted

layer_size

The layer size in pixels

layers: list[PlotLayer]

Single data visualization layers (the real plots)

margins

Margin around the main layers in pixels on each side (left, top, right, bottom)

row

Row in which the plot is displayed. Auto-assigned by the figure

size: Size2D

Plot’s effective size in pixels (as far as defined)

target_size

Desired target size in pixels

title

The plot’s title

title_color

The title’s color

title_height

The title’s size in pixels

title_spacing: tuple[float, float]

Space above and below the title