Canvas2D

class scenepic.Canvas2D

A 2D canvas that can contain a number of Frame2Ds.

property background_color

The background color of the frame

Type:

np.ndarray

property canvas_id

A unique identifier for the canvas

Type:

str

clear_script()

Call this if you are dumping a ScenePic script in multiple parts, e.g. for client-server interactions, or when chunking a large visualization into multiple files.

create_frame()

Creates a new Frame2D object and appends to the list of Frame2Ds in the Canvas2D.

Parameters:

frame_id (str) – a unique identifier for the Frame2D (will be automatically populated if not provided).

Returns:

a new Frame2D object

Return type:

Frame2D

property height

The height of the Canvas

Type:

float

property media_id

The ID of the attached media file.

This file will be used to drive playback, i.e. frames will be displayed in time with the playback of the media file.

Type:

str

set_layer_settings(layer_settings)

Specify the visibilities and opacities of certain mesh layers.

Description:

Each Mesh object can optionally be part of a user-identified layer (see Mesh constructor). Calling set_layer_settings will result in an additional drop-down selector in the ScenePic user interface.

Parameters:
  • self (Canvas2D) – the self reference

  • layer_settings (Mapping[str, Union[dict, LayerSettings]]) – a mapping from layer IDs to layer settings.

property width

The width of the Canvas

Type:

float

Frame2D

class scenepic.Frame2D

Represents a frame of a 2D animation

add_circle(x, y, radius, line_color=None, line_width=1.0, fill_color=None, layer_id='')

Add a circle to the frame.

Parameters:
  • self (Frame2D) – the self reference

  • x (float) – the center x coordinate

  • y (float) – the center y coordinate

  • radius (float) – the radius of the circle

  • line_color (np.ndarray, optional) – the color of the line. Defaults to Black.

  • line_width (float, optional) – the width of the line. Defaults to 1.0.

  • fill_color (np.ndarray, optional) – the fill color to use. Defaults to None.

  • layer_id (str, optional) – Unique ID of the layer associated with this primitive. Defaults to “”.

add_image(image_id, position_type='fit', x=0.0, y=0.0, scale=1.0, smoothed=False, layer_id='')

Add an image to the frame.

Parameters:
  • self (Frame2D) – the self reference

  • image_id (str) – the unique identifier of the image

  • position_type (str, optional) – one of “fit”, “fill”, “stretch”, or “manual”. Defaults to “fit”.

  • x (float, optional) – x coordinate to draw image at if position_type == “manual”. Defaults to 0.0.

  • y (float, optional) – y coordinate to draw image at if position_type == “manual”. Defaults to 0.0.

  • scale (float, optional) – scale factor to draw image by if position_type == “manual”. Defaults to 1.0.

  • smoothed (bool, optional) – whether to draw an image with smoothing or using nearest neighbor. Defaults to False.

  • layer_id (str, optional) – Unique ID of the layer associated with this primitive. Defaults to “”.

add_line()

Add a line to the frame.

Parameters:
  • coordinates (np.ndarray) – float32 matrix of [N, 2] coordinates of the line

  • line_color (np.ndarray, optional) – the color of the line. Defaults to Black.

  • line_width (float, optional) – the width of the line. Defaults to 1.0.

  • fill_color (np.ndarray, optional) – the fill color to use. Defaults to None.

  • close_path (bool, optional) – whether to close the path. Defaults to False.

  • layer_id (str, optional) – Unique ID of the layer associated with this primitive. Defaults to “”.

add_rectangle()

Add a rectangle to the frame.

Parameters:
  • x (float) – the upper left corner x coordinate

  • y (float) – the upper left corner y coordinate

  • w (float) – the width of the rectangle

  • h (float) – the height of the rectangle

  • line_color (np.ndarray, optional) – the color of the line. Defaults to Black.

  • line_width (float, optional) – the width of the line. Defaults to 1.0.

  • fill_color (np.ndarray, optional) – the fill color to use. Defaults to None.

  • layer_id (str, optional) – Unique ID of the layer associated with this primitive. Defaults to “”.

add_text(text, left, bottom, color=None, size_in_pixels=12.0, font_family='sans-serif', layer_id='')

Add some text to the frame.

Parameters:
  • self (Frame2D) – The self reference

  • text (str) – the text to display

  • left (float) – the pixel position of the left side of the text

  • bottom (float) – the pixel position of the bottom of the text

  • color (np.ndarray, optional) – the color of the text. Defaults to White.

  • size_in_pixels (float, optional) – the vertical size of the text in pixels. Defaults to 12.0.

  • font_family (str, optional) – the font to use for the text. Defaults to “sans-serif”.

  • layer_id (str, optional) – Unique ID of the layer associated with this primitive. Defaults to “”.

add_video()

Add an frame from a video to the frame.

Parameters:
  • position_type (str, optional) – one of “fit”, “fill”, “stretch”, or “manual”. Defaults to “fit”.

  • x (float, optional) – x coordinate to draw video at if position_type == “manual”. Defaults to 0.0.

  • y (float, optional) – y coordinate to draw video at if position_type == “manual”. Defaults to 0.0.

  • scale (float, optional) – scale factor to draw video by if position_type == “manual”. Defaults to 1.0.

  • smoothed (bool, optional) – whether to draw an video with smoothing or using nearest neighbor. Defaults to False.

  • layer_id (str, optional) – Unique ID of the layer associated with this primitive. Defaults to “”.

Graph

class scenepic.Graph

A 2D viewport that animates one or more sparklines.

class Margin

Represents the margin along the edges of a graph.

Parameters:
  • size (float, optional) – space in pixels to use for all margins. Default 10.

  • top (float, optional) – the top margin value in pixels

  • right (float, optional) – the right margin value in pixels

  • bottom (float, optional) – the bottom margin value in pixels

  • left (float, optional) – the left margin value in pixels

property bottom

The bottom margin in pixels

Type:

float

property left

The left margin in pixels

Type:

float

property right

The right margin in pixels

Type:

float

property top

The top margin in pixels

Type:

float

class VerticalRule

Represents a vertical rule drawn on a sparkline graph.

Parameters:
  • frame (int) – Frame to add the vertical rule

  • color – (Color, optional): the line color. Defauts to black.

  • line_width – (float, optional): The line width in pixels. Defaults to 1.0f.

property color

the color of the line

Type:

Color

property frame

the frame at which to add the line

Type:

int

property line_width

the width of the line in pixels

Type:

float

add_sparkline()

Adds a sparkline to the graph.

Parameters:
  • name (str) – the name of the measured quantity

  • values (np.ndarray) – the measured values

  • line_color (Color, optional) – the color of the line (and its labels). Defaults to Black.

  • line_width (float, optional) – The width of the line. Defaults to 1.0.

  • vertical_rules (List[VerticalRule], optional) – the vertical rules to add. Defaults to None.

property background_color

The background color of the frame

Type:

np.ndarray

property canvas_id

A unique identifier for the canvas

Type:

str

property font_family

The font family used for the graph labels

Type:

str

property margin

The outside margin of the graph

Type:

Margin

property media_id

The ID of the attached media file.

This file will be used to drive playback, i.e. frames will be displayed in time with the playback of the media file.

Type:

str

property name_align

The alignment of the sparkline labels. One of (‘left’, ‘right’, ‘top’, ‘bottom’, or ‘none’)

property name_size

The size of the sparkline labels in pixels

Type:

float

property value_align

The alignment of the sparkline values. One of (‘left’, ‘right’, ‘top’, ‘bottom’, or ‘none’)

property value_size

The size of the sparkline labels in pixels

Type:

float