scistag.plotstag.figure.Figure

class Figure(cols=1, rows=1, dims=None, size=None, count=None, plot_size=None, scaling=1.0, stepping='rightDown', borderless=False)

Bases: object

Defines a canvas onto which one or multiple :class:`Plot`s may be printed, manages their appearance, their behavior and different methods to rasterize or export plots.

Parameters
  • rows (int) – The number of rows

  • cols (int | None) – The number of columns

  • dims (tuple[int | None, int | None] | None) –

    The count of columns and rows as tuple. Overwrites rows and columns if provided.

    Examples:

  • size (Size2DTypes | None) –

    The (precise) target size in pixels.

    Great for plotting diagrams etc. with precise size, not well suited for images and matrices. Prefer plot_default_size for such data types.

  • count (int | None) – If specified it will automatically adjust the row count to be able to store all elements. If columns is explicitly set to None it will adjust the column count instead.

  • plot_size (tuple[float, float] | None) – The area provided per plot if no other size is enforced. Adapts better to the size of images and matrices.

  • scaling (float) – The figure’s DPI based scaling factor (1.0 = 96 DPI)

  • stepping (GridSteppingMode | str) –

    Defines the mode and order in which the cursor iterates through the figure when using for plot in figure. See GridSteppingMode

    Also allows short-codes such as “rightDown”, “rd” or “downRight” as defined in GridSteppingMode.

  • borderless (bool) – If set to true by default all borders and margins will be removed for the figure and all plots.

Methods

add_matplot

Adds a matplotlib layer and provides access to the matplot functions

add_plot

Adds an empty plot at given location.

borderless

Removes all borders from the figure and (if set so) by default from all sub plots.

get_location

Returns the location of given grid by enumeration index.

render

Renders the figure and returns it as image

set_plot

Updates a plot ot a specific index.

set_stepping_mode

Changes the behavior in which order the single grids of this figure are iterated and indexed.

set_title

Sets the plot's title

update_layouts

Updates the layouting of all plots and the own size

update_margins

Updates the figure's margins

Attributes

__dict__

__doc__

__module__

__weakref__

list of weak references to the object (if defined)

_determine_col_row_sizes()

Determines the efficient size of all plots :rtype: tuple[list[float], list[float]] :return: The width of the single columns and the height of the single

rows.

_get_target_plot_size()

Returns the target size of the defined plot (if a target size was defined).

Return type

Size2D | None

Returns

The size in pixels

_render_plots(canvas)

Renders the single plots

Parameters

canvas – The target canvas

_render_single_plot(canvas, cur_col, cur_row, x_off, y_off)

Renders a single plot

Parameters
  • canvas – The tagret canvsa

  • cur_col – The current column

  • cur_row – The current row

  • x_off – The x offset

  • y_off – The y offset

_repr_png_()

Returns the IPython PNG representation

Return type

bytes

Returns

PNG data as bytes

_update_blocked_space()

Updates the blocked space computation to determine how much space is available for the plots

add_matplot(col=0, row=0, size_ratio=1.0, **params)

Adds a matplotlib layer and provides access to the matplot functions

Usage:

Parameters
  • col (int) – The plot’s column

  • row (int) – The plot’s row

  • size_ratio (float) – The size ratio with which the matplot shall be integrated. By default the original size

  • params – The parameters which shall be passed into the figure which is going to be created.

Return type

MPLayerLock

Returns

The lock handle

add_plot(col=0, row=0)

Adds an empty plot at given location.

If a plot was already assigned the existing plot will be returned.

Parameters
  • col (int) – The plot’s column

  • row (int) – The plot’s row

Return type

Plot

Returns

The plot

borderless(mode='all')

Removes all borders from the figure and (if set so) by default from all sub plots.

Parameters

mode (Literal[‘figure’, ‘plot’, ‘all’]) – The removal mode. * “figure” - Just remove figure border * “plot” - Just remove plot borders * “all” - Remove borders from figure and all plots (by default)

Return type

Figure

Returns

get_location(enum_index)

Returns the location of given grid by enumeration index.

Note: In which order the grids are processed is defined by iteration_stepping so index 0 is not necessarily 0, 0 but e.g. in a stepping from the upper left corner could also start at 0, row_count-1.

Parameters

enum_index (int) – The enumeration index (from 0 .. col*row -1)

Return type

tuple[int | None, int | None]

Returns

The column and row of the grid, None if index is out of range

render()

Renders the figure and returns it as image

Return type

Image

Returns

The visualization of the plot as Image

set_plot(plot, column=0, row=0)

Updates a plot ot a specific index.

If not index is specified it will define the main plot (0,0).

Parameters
  • plot (Plot) – The plot to be assigned to given column and row index

  • column (int) – The plot’s column

  • row (int) – The plot’s row

Returns

set_stepping_mode(mode)

Changes the behavior in which order the single grids of this figure are iterated and indexed. By default the cursor moves from left ro right and then continues in the next row.

With other modes you can for example fill the grid in a different order, e.g. from to to bottom, see GridSteppingMode.

Parameters

mode (GridSteppingMode) – The new mode

set_title(title)

Sets the plot’s title

Parameters

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

Return type

Figure

Returns

The plot

update_layouts()

Updates the layouting of all plots and the own size

update_margins()

Updates the figure’s margins