Scenegraph

The vispy.scene subpackage provides high-level, flexible, and easy to use functionality for creating scenes composed of multiple visual objects.

Overview

Scenegraphs are a commonly used system for describing a scene as a hierarchy of visual objects. Users need only create these visual objects and specify their location in the scene, and the scenegraph system will automatically draw the entire scene whenever an update is required.

Using the vispy scenegraph requires only a few steps:

  1. Create a SceneCanvas to display the scene. This object has a scene property that is the top-level Node in the scene.
  2. Create one or more Node instances (see vispy.scene.visuals)
  3. Add these Node instances to the scene by making them children of canvas.scene, or children of other nodes that are already in the scene.

For more information see:

  • complete scenegraph documentation
  • scene examples
  • scene API reference

vispy.scene.cameras

Cameras are responsible for determining which part of a scene is displayed in a viewbox and for handling user input to change the view.

Several Camera subclasses are available to customize the projection of the scene such as 3D perspective and orthographic projections, 2D scale/translation, and other specialty cameras. A variety of user interaction styles are available for each camera including arcball, turntable, first-person, and pan/zoom interactions.

Internally, Cameras work by setting the transform of a SubScene object such that a certain part of the scene is mapped to the bounding rectangle of the ViewBox.

class vispy.scene.cameras.ArcballCamera(fov=0.0, distance=None, **kwargs)[source]

Bases: vispy.scene.cameras.perspective.Base3DRotationCamera

3D camera class that orbits around a center point while maintaining a view on a center point.

For this camera, the scale_factor indicates the zoom level, and the center indicates the position to put at the center of the view.

Parameters:

fov : float

Field of view. Zero (default) means orthographic projection.

distance : float | None

The distance of the camera from the rotation point (only makes sense if fov > 0). If None (default) the distance is determined from the scale_factor and fov.

**kwargs : dict

Keyword arguments to pass to BaseCamera.

Notes

Interaction:

  • LMB: orbits the view around its center point.
  • RMB or scroll: change scale_factor (i.e. zoom level)
  • SHIFT + LMB: translate the center point
  • SHIFT + RMB: change FOV
class vispy.scene.cameras.BaseCamera(interactive=True, flip=None, up='+z', parent=None, name=None)[source]

Bases: vispy.scene.node.Node

Base camera class.

The Camera describes the perspective from which a ViewBox views its subscene, and the way that user interaction affects that perspective.

Most functionality is implemented in subclasses. This base class has no user interaction and causes the subscene to use the same coordinate system as the ViewBox.

Parameters:

interactive : bool

Whether the camera processes mouse and keyboard events.

flip : tuple of bools

For each dimension, specify whether it is flipped.

up : {‘+z’, ‘-z’, ‘+y’, ‘-y’, ‘+x’, ‘-x’}

The direction that is considered up. Default ‘+z’. Not all camera’s may support this (yet).

parent : Node

The parent of the camera.

name : str

Name used to identify the camera in the scene.

center

The center location for this camera

The exact meaning of this value differs per type of camera, but generally means the point of interest or the rotation point.

depth_value

The depth value to use in orthographic and perspective projection

For orthographic projections, depth_value is the distance between the near and far clipping planes. For perspective projections, it is the ratio between the near and far clipping plane distances.

GL has a fixed amount of precision in the depth buffer, and a fixed constant will not work for both a very large range and very high precision. This property provides the user a way to override the default value if necessary.

fov

Field-of-view angle of the camera. If 0, the camera is in orthographic mode.

get_state()[source]

Get the current view state of the camera

Returns a dict of key-value pairs. The exact keys depend on the camera. Can be passed to set_state() (of this or another camera of the same type) to reproduce the state.

interactive

Boolean describing whether the camera should enable or disable user interaction.

Link this camera with another camera of the same type

Linked camera’s keep each-others’ state in sync.

Parameters:

camera : instance of Camera

The other camera to link.

on_canvas_change(event)[source]

Canvas change event handler

Parameters:

event : instance of Event

The event.

pre_transform

A transform to apply to the beginning of the scene transform, in addition to anything else provided by this Camera.

reset()[source]

Reset the view to the default state.

set_default_state()[source]

Set the current state to be the default state to be applied when calling reset().

set_range(x=None, y=None, z=None, margin=0.05)[source]

Set the range of the view region for the camera

Parameters:

x : tuple | None

X range.

y : tuple | None

Y range.

z : tuple | None

Z range.

margin : float

Margin to use.

Notes

The view is set to the given range or to the scene boundaries if ranges are not specified. The ranges should be 2-element tuples specifying the min and max for each dimension.

For the PanZoomCamera the view is fully defined by the range. For e.g. the TurntableCamera the elevation and azimuth are not set. One should use reset() for that.

set_state(state=None, **kwargs)[source]

Set the view state of the camera

Should be a dict (or kwargs) as returned by get_state. It can be an incomlete dict, in which case only the specified properties are set.

Parameters:

state : dict

The camera state.

**kwargs : dict

Unused keyword arguments.

up

The dimension that is considered up.

view_changed()[source]

Called when this camera is changes its view. Also called when its associated with a viewbox.

viewbox

The viewbox that this camera applies to.

viewbox_key_event(event)[source]

ViewBox key event handler

Parameters:

event : instance of Event

The event.

viewbox_mouse_event(event)[source]

Viewbox mouse event handler

Parameters:

event : instance of Event

The event.

viewbox_resize_event(event)[source]

The ViewBox resize handler to update the transform

Parameters:

event : instance of Event

The event.

class vispy.scene.cameras.FlyCamera(fov=60, rotation=None, **kwargs)[source]

Bases: vispy.scene.cameras.perspective.PerspectiveCamera

The fly camera provides a way to explore 3D data using an interaction style that resembles a flight simulator.

For this camera, the scale_factor indicates the speed of the camera in units per second, and the center indicates the position of the camera.

Parameters:

fov : float

Field of view. Default 60.0.

rotation : float | None

Rotation to use.

**kwargs : dict

Keyword arguments to pass to BaseCamera.

Notes

Interacting with this camera might need a bit of practice. The reaction to key presses can be customized by modifying the keymap property.

Moving:

  • arrow keys, or WASD to move forward, backward, left and right
  • F and C keys move up and down
  • Space bar to brake

Viewing:

  • Use the mouse while holding down LMB to control the pitch and yaw.
  • Alternatively, the pitch and yaw can be changed using the keys IKJL
  • The camera auto-rotates to make the bottom point down, manual rolling can be performed using Q and E.
auto_roll

Whether to rotate the camera automaticall to try and attempt to keep Z up.

keymap

A dictionary that maps keys to thruster directions

The keys in this dictionary are vispy key descriptions (from vispy.keys) or characters that represent keys. These are matched to the “key” attribute of key-press and key-release events.

The values are tuples, in which the first element specifies the magnitude of the acceleration, using negative values for “backward” thrust. A value of zero means to brake. The remaining elements specify the dimension to which the acceleration should be applied. These are 1, 2, 3 for forward/backward, left/right, up/down, and 4, 5, 6 for pitch, yaw, roll.

on_timer(event)[source]

Timer event handler

Parameters:

event : instance of Event

The event.

rotation

Get the full rotation. This rotation is composed of the normal rotation plus the extra rotation due to the current interaction of the user.

viewbox_key_event(event)[source]

ViewBox key event handler

Parameters:

event : instance of Event

The event.

viewbox_mouse_event(event)[source]

ViewBox mouse event handler

Parameters:

event : instance of Event

The event.

class vispy.scene.cameras.MagnifyCamera(size_factor=0.25, radius_ratio=0.9, **kwargs)[source]

Bases: vispy.scene.cameras.panzoom.PanZoomCamera

Camera implementing a MagnifyTransform combined with PanZoomCamera.

Parameters:

size_factor : float

The size factor to use.

radius_ratio : float

The radius ratio to use.

**kwargs : dict

Keyword arguments to pass to PanZoomCamera and create a transform.

Notes

This Camera uses the mouse cursor position to set the center position of the MagnifyTransform, and uses mouse wheel events to adjust the magnification factor.

At high magnification, very small mouse movements can result in large changes, so we use a timer to animate transitions in the transform properties.

The camera also adjusts the size of its “lens” area when the view is resized.

on_timer(event=None)[source]

Timer event handler

Parameters:

event : instance of Event

The timer event.

transform_class[source]

alias of MagnifyTransform

viewbox_mouse_event(event)[source]

ViewBox mouse event handler

Parameters:

event : instance of Event

The mouse event.

viewbox_resize_event(event)[source]

ViewBox resize event handler

Parameters:

event : instance of Event

The viewbox resize event.

class vispy.scene.cameras.Magnify1DCamera(size_factor=0.25, radius_ratio=0.9, **kwargs)[source]

Bases: vispy.scene.cameras.magnify.MagnifyCamera

Camera implementing a MagnifyTransform combined with PanZoomCamera.

Parameters:

size_factor : float

The size factor to use.

radius_ratio : float

The radius ratio to use.

**kwargs : dict

Keyword arguments to pass to PanZoomCamera and create a transform.

Notes

This Camera uses the mouse cursor position to set the center position of the MagnifyTransform, and uses mouse wheel events to adjust the magnification factor.

At high magnification, very small mouse movements can result in large changes, so we use a timer to animate transitions in the transform properties.

The camera also adjusts the size of its “lens” area when the view is resized.

transform_class[source]

alias of Magnify1DTransform

class vispy.scene.cameras.PanZoomCamera(rect=(0, 0, 1, 1), aspect=None, **kwargs)[source]

Bases: vispy.scene.cameras.base_camera.BaseCamera

Camera implementing 2D pan/zoom mouse interaction.

For this camera, the scale_factor indicates the zoom level, and the center indicates the center position of the view.

By default, this camera inverts the y axis of the scene. This usually results in the scene +y axis pointing upward because widgets (including ViewBox) have their +y axis pointing downward.

Parameters:

rect : Rect

A Rect object or 4-element tuple that specifies the rectangular area to show.

aspect : float | None

The aspect ratio (i.e. scaling) between x and y dimension of the scene. E.g. to show a square image as square, the aspect should be 1. If None (default) the x and y dimensions are scaled independently.

**kwargs : dict

Keyword arguments to pass to BaseCamera.

Notes

Interaction:

  • LMB: pan the view
  • RMB or scroll: zooms the view
aspect

The ratio between the x and y dimension. E.g. to show a square image as square, the aspect should be 1. If None, the dimensions are scaled automatically, dependening on the available space. Otherwise the ratio between the dimensions is fixed.

pan(*pan)[source]

Pan the view.

Parameters:

*pan : length-2 sequence

The distance to pan the view, in the coordinate system of the scene.

rect

The rectangular border of the ViewBox visible area, expressed in the coordinate system of the scene.

Note that the rectangle can have negative width or height, in which case the corresponding dimension is flipped (this flipping is independent from the camera’s flip property).

viewbox_mouse_event(event)[source]

The SubScene received a mouse event; update transform accordingly.

Parameters:

event : instance of Event

The event.

viewbox_resize_event(event)[source]

Modify the data aspect and scale factor, to adjust to the new window size.

Parameters:

event : instance of Event

The event.

zoom(factor, center=None)[source]

Zoom in (or out) at the given center

Parameters:

factor : float or tuple

Fraction by which the scene should be zoomed (e.g. a factor of 2 causes the scene to appear twice as large).

center : tuple of 2-4 elements

The center of the view. If not given or None, use the current center.

class vispy.scene.cameras.TurntableCamera(fov=0.0, elevation=30.0, azimuth=30.0, roll=0.0, distance=None, **kwargs)[source]

Bases: vispy.scene.cameras.perspective.Base3DRotationCamera

3D camera class that orbits around a center point while maintaining a view on a center point.

For this camera, the scale_factor indicates the zoom level, and the center indicates the position to put at the center of the view.

Parameters:

fov : float

Field of view. Zero (default) means orthographic projection.

elevation : float

Elevation angle in degrees. Positive angles place the camera above the cente point, negative angles place the camera below the center point.

azimuth : float

Azimuth angle in degrees. Zero degrees places the camera on the positive x-axis, pointing in the negative x direction.

roll : float

Roll angle in degrees

distance : float | None

The distance of the camera from the rotation point (only makes sense if fov > 0). If None (default) the distance is determined from the scale_factor and fov.

**kwargs : dict

Keyword arguments to pass to BaseCamera.

Notes

Interaction:

  • LMB: orbits the view around its center point.
  • RMB or scroll: change scale_factor (i.e. zoom level)
  • SHIFT + LMB: translate the center point
  • SHIFT + RMB: change FOV
azimuth

The angle of the camera in degrees around the y axis. An angle of 0 places the camera within the (y, z) plane.

elevation

The angle of the camera in degrees above the horizontal (x, z) plane.

orbit(azim, elev)[source]

Orbits the camera around the center position.

Parameters:

azim : float

Angle in degrees to rotate horizontally around the center point.

elev : float

Angle in degrees to rotate vertically around the center point.

roll

The angle of the camera in degrees around the z axis. An angle of 0 places puts the camera upright.


vispy.scene.canvas

class vispy.scene.canvas.SceneCanvas(title='VisPy canvas', size=(800, 600), position=None, show=False, autoswap=True, app=None, create_native=True, vsync=False, resizable=True, decorate=True, fullscreen=False, config=None, shared=None, keys=None, parent=None, dpi=None, always_on_top=False, px_scale=1, bgcolor='black')[source]

Bases: vispy.app.canvas.Canvas, vispy.util.frozen.Frozen

A Canvas that automatically draws the contents of a scene

Parameters:

title : str

The widget title

size : (width, height)

The size of the window.

position : (x, y)

The position of the window in screen coordinates.

show : bool

Whether to show the widget immediately. Default False.

autoswap : bool

Whether to swap the buffers automatically after a draw event. Default True. If True, the swap_buffers Canvas method will be called last (by default) by the canvas.draw event handler.

app : Application | str

Give vispy Application instance to use as a backend. (vispy.app is used by default.) If str, then an application using the chosen backend (e.g., ‘pyglet’) will be created. Note the canvas application can be accessed at canvas.app.

create_native : bool

Whether to create the widget immediately. Default True.

vsync : bool

Enable vertical synchronization.

resizable : bool

Allow the window to be resized.

decorate : bool

Decorate the window. Default True.

fullscreen : bool | int

If False, windowed mode is used (default). If True, the default monitor is used. If int, the given monitor number is used.

config : dict

A dict with OpenGL configuration options, which is combined with the default configuration options and used to initialize the context. See canvas.context.config for possible options.

shared : Canvas | GLContext | None

An existing canvas or context to share OpenGL objects with.

keys : str | dict | None

Default key mapping to use. If ‘interactive’, escape and F11 will close the canvas and toggle full-screen mode, respectively. If dict, maps keys to functions. If dict values are strings, they are assumed to be Canvas methods, otherwise they should be callable.

parent : widget-object

The parent widget if this makes sense for the used backend.

dpi : float | None

Resolution in dots-per-inch to use for the canvas. If dpi is None, then the value will be determined by querying the global config first, and then the operating system.

always_on_top : bool

If True, try to create the window in always-on-top mode.

px_scale : int > 0

A scale factor to apply between logical and physical pixels in addition to the actual scale factor determined by the backend. This option allows the scale factor to be adjusted for testing.

bgcolor : Color

The background color to use.

See also

vispy.app.Canvas

Notes

Receives the following events:

  • initialize
  • resize
  • draw
  • mouse_press
  • mouse_release
  • mouse_double_click
  • mouse_move
  • mouse_wheel
  • key_press
  • key_release
  • stylus
  • touch
  • close

The ordering of the mouse_double_click, mouse_press, and mouse_release events are not guaranteed to be consistent between backends. Only certain backends natively support double-clicking (currently Qt and WX); on other backends, they are detected manually with a fixed time delay. This can cause problems with accessibility, as increasing the OS detection time or using a dedicated double-click button will not be respected.

central_widget

Returns the default widget that occupies the entire area of the canvas.

draw_visual(visual, event=None)[source]

Draw a visual and its children to the canvas or currently active framebuffer.

Parameters:

visual : Visual

The visual to draw

event : None or DrawEvent

Optionally specifies the original canvas draw event that initiated this draw.

on_close(event)[source]

Close event handler

Parameters:

event : instance of Event

The event.

on_draw(event)[source]

Draw handler

Parameters:

event : instance of Event

The draw event.

on_resize(event)[source]

Resize handler

Parameters:

event : instance of Event

The resize event.

pop_fbo()[source]

Pop an FBO from the stack.

pop_viewport()[source]

Pop a viewport from the stack.

push_fbo(fbo, offset, csize)[source]

Push an FBO on the stack.

This activates the framebuffer and causes subsequent rendering to be written to the framebuffer rather than the canvas’s back buffer. This will also set the canvas viewport to cover the boundaries of the framebuffer.

Parameters:

fbo : instance of FrameBuffer

The framebuffer object .

offset : tuple

The location of the fbo origin relative to the canvas’s framebuffer origin.

csize : tuple

The size of the region in the canvas’s framebuffer that should be covered by this framebuffer object.

push_viewport(viewport)[source]

Push a viewport (x, y, w, h) on the stack. Values must be integers relative to the active framebuffer.

Parameters:

viewport : tuple

The viewport as (x, y, w, h).

render(region=None, size=None, bgcolor=None)[source]

Render the scene to an offscreen buffer and return the image array.

Parameters:

region : tuple | None

Specifies the region of the canvas to render. Format is (x, y, w, h). By default, the entire canvas is rendered.

size : tuple | None

Specifies the size of the image array to return. If no size is given, then the size of the region is used, multiplied by the pixel scaling factor of the canvas (see pixel_scale). This argument allows the scene to be rendered at resolutions different from the native canvas resolution.

bgcolor : instance of Color | None

The background color to use.

Returns:

image : array

Numpy array of type ubyte and shape (h, w, 4). Index [0, 0] is the upper-left corner of the rendered region.

scene

The SubScene object that represents the root node of the scene graph to be displayed.

update(node=None)[source]

Update the scene

Parameters:

node : instance of Node

Not used.

visual_at(pos)[source]

Return the visual at a given position

Parameters:

pos : tuple

The position in logical coordinates to query.

Returns:

visual : instance of Visual | None

The visual at the position, if it exists.

visuals_at(pos, radius=10)[source]

Return a list of visuals within radius pixels of pos.

Visuals are sorted by their proximity to pos.

Parameters:

pos : tuple

(x, y) position at which to find visuals.

radius : int

Distance away from pos to search for visuals.


vispy.scene.node

class vispy.scene.node.Node(parent=None, name=None, transforms=None)[source]

Bases: object

Base class representing an object in a scene.

A group of nodes connected through parent-child relationships define a scenegraph. Nodes may have any number of children.

Each Node defines a transform property, which describes the position, orientation, scale, etc. of the Node relative to its parent. The Node’s children inherit this property, and then further apply their own transformations on top of that.

With the transform property, each Node implicitly defines a “local” coordinate system, and the Nodes and edges in the scenegraph can be thought of as coordinate systems connected by transformation functions.

Parameters:

parent : Node

The parent of the Node.

name : str

The name used to identify the node.

transforms : instance of TransformSystem | None

The associated transforms.

canvas

The canvas in which this node’s scenegraph is being drawn.

children

A copy of the list of children of this node. Do not add items to this list, but use x.parent = y instead.

clip_children

Boolean indicating whether children of this node will inherit its clipper.

clipper

A visual filter that can be used to clip visuals to the boundaries of this node.

common_parent(node)[source]

Return the common parent of two entities

If the entities have no common parent, return None.

Parameters:

node : instance of Node

The other node.

Returns:

parent : instance of Node | None

The parent.

describe_tree(with_transform=False)[source]

Create tree diagram of children

Parameters:

with_transform : bool

If true, add information about node transform types.

Returns:

tree : str

The tree diagram.

document

The document is an optional property that is an node representing the coordinate system from which this node should make physical measurements such as px, mm, pt, in, etc. This coordinate system should be used when determining line widths, font sizes, and any other lengths specified in physical units.

The default is None; in this case, a default document is used during drawing (usually this is supplied by the SceneCanvas).

document_node

The node to be used as the document coordinate system.

By default, the document node is self.root_node.

is_child(node)[source]

Check if a node is a child of the current node

Parameters:

node : instance of Node

The potential child.

Returns:

child : bool

Whether or not the node is a child.

node_path(node)[source]

Return two lists describing the path from this node to another

Parameters:

node : instance of Node

The other node.

Returns:

p1 : list

First path (see below).

p2 : list

Second path (see below).

Notes

The first list starts with this node and ends with the common parent between the endpoint nodes. The second list contains the remainder of the path from the common parent to the specified ending node.

For example, consider the following scenegraph:

A --- B --- C --- D
                           --- E --- F

Calling D.node_path(F) will return:

([D, C, B], [E, F])
node_path_to_child(node)[source]

Return a list describing the path from this node to a child node

If node is not a (grand)child of this node, then raise RuntimeError.

Parameters:

node : instance of Node

The child node.

Returns:

path : list | None

The path.

node_path_transforms(node)[source]

Return the list of transforms along the path to another node.

The transforms are listed in reverse order, such that the last transform should be applied first when mapping from this node to the other.

Parameters:

node : instance of Node

The other node.

Returns:

transforms : list

A list of Transform instances.

node_transform(node)[source]

Return the transform that maps from the coordinate system of self to the local coordinate system of node.

Note that there must be a _single_ path in the scenegraph that connects the two entities; otherwise an exception will be raised.

Parameters:

node : instance of Node

The other node.

Returns:

transform : instance of ChainTransform

The transform.

on_parent_change(event)[source]

Parent change event handler

Parameters:

event : instance of Event

The event.

order

A value used to determine the order in which nodes are drawn.

Greater values are drawn later. Children are always drawn after their parent.

parent

The parent of this node in the scenegraph.

Nodes inherit coordinate transformations and some filters (opacity and clipping by default) from their parents. Setting this property assigns a new parent, changing the topology of the scenegraph.

May be set to None to remove this node (and its children) from a scenegraph.

parent_chain()[source]

Return the list of parents starting from this node. The chain ends at the first node with no parents.

picking

Boolean that determines whether this node (and its children) are drawn in picking mode.

scene_node

The first ancestor of this node that is a SubScene instance, or self if no such node exists.

set_transform(type_, *args, **kwargs)[source]

Create a new transform of type and assign it to this node.

All extra arguments are used in the construction of the transform.

Parameters:

type_ : str

The transform type.

*args : tuple

Arguments.

**kwargs : dict

Keywoard arguments.

transform

The transform that maps the local coordinate frame to the coordinate frame of the parent.

update()[source]

Emit an event to inform listeners that properties of this Node have changed. Also request a canvas update.

visible

Whether this node should be drawn or not. Only applicable to nodes that can be drawn.


vispy.scene.events

class vispy.scene.events.SceneMouseEvent(event, visual)[source]

Bases: vispy.util.event.Event

Represents a mouse event that occurred on a SceneCanvas. This event is delivered to all entities whose mouse interaction area is under the event.

button

The button pressed or released on this event.

buttons

A list of all buttons currently pressed on the mouse.

delta

The increment by which the mouse wheel has moved.

last_event

The mouse event immediately prior to this one. This property is None when no mouse buttons are pressed.

pos

The position of this event in the local coordinate system of the visual.

press_event

The mouse press event that initiated a mouse drag, if any.


vispy.scene.visuals

The classes in scene.visuals are visuals that may be added to a scenegraph using the methods and properties defined in vispy.scene.Node such as name, visible, parent, children, etc…

These classes are automatically generated by mixing vispy.scene.Node with the Visual classes found in vispy.visuals.

For developing custom visuals, it is recommended to subclass from vispy.visuals.Visual rather than vispy.scene.Node.

class vispy.scene.visuals.Arrow(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.line.arrow.ArrowVisual

Arrow visual

This class inherits from visuals.ArrowVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

A special line visual which can also draw optional arrow heads at the specified vertices.

You add an arrow head by specifying two vertices v1 and v2 which represent the arrow body. This visual will draw an arrow head using v2 as center point, and the orientation of the arrow head is automatically determined by calculating the direction vector between v1 and v2.

Parameters:

pos : array

Array of shape (…, 2) or (…, 3) specifying vertex coordinates.

color : Color, tuple, or array

The color to use when drawing the line. If an array is given, it must be of shape (…, 4) and provide one rgba color per vertex. Can also be a colormap name, or appropriate Function.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

width:

The width of the line in px. Line widths > 1px are only guaranteed to work when using ‘agg’ method.

connect : str or array

Determines which vertices are connected by lines.

  • “strip” causes the line to be drawn with each vertex connected to the next.
  • “segments” causes each pair of vertices to draw an independent line segment
  • numpy arrays specify the exact set of segment pairs to connect.

method : str

Mode to use for drawing.

  • “agg” uses anti-grain geometry to draw nicely antialiased lines with proper joins and endcaps.
  • “gl” uses OpenGL’s built-in line rendering. This is much faster, but produces much lower-quality results and is not guaranteed to obey the requested line width or join/endcap styles.

antialias : bool

Enables or disables antialiasing. For method=’gl’, this specifies whether to use GL’s line smoothing, which may be unavailable or inconsistent on some platforms.

arrows : array

A (N, 4) or (N, 6) matrix where each row contains the (x, y) or the (x, y, z) coordinate of the first and second vertex of the arrow body. Remember that the second vertex is used as center point for the arrow head, and the first vertex is only used for determining the arrow head orientation.

arrow_type : string

Specify the arrow head type, the currently available arrow head types are:

  • stealth
  • curved
  • triangle_30
  • triangle_60
  • triangle_90
  • angle_30
  • angle_60
  • angle_90
  • inhibitor_round

arrow_size : float

Specify the arrow size

arrow_color : Color, tuple, or array

The arrow head color. If an array is given, it must be of shape (…, 4) and provide one rgba color per arrow head. Can also be a colormap name, or appropriate Function.

class vispy.scene.visuals.Axis(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.axis.AxisVisual

Axis visual

This class inherits from visuals.AxisVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

pos : array

Co-ordinates of start and end of the axis.

domain : tuple

The data values at the beginning and end of the axis, used for tick labels. i.e. (5, 10) means the axis starts at 5 and ends at 10. Default is (0, 1).

tick_direction : array

The tick direction to use (in document coordinates).

scale_type : str

The type of scale. For now only ‘linear’ is supported.

axis_color : tuple

RGBA values for the axis colour. Default is black.

tick_color : tuple

RGBA values for the tick colours. The colour for the major and minor ticks is currently fixed to be the same. Default is a dark grey.

text_color : Color

The color to use for drawing tick and axis labels

minor_tick_length : float

The length of minor ticks, in pixels

major_tick_length : float

The length of major ticks, in pixels

tick_width : float

Line width for the ticks

tick_label_margin : float

Margin between ticks and tick labels

tick_font_size : float

The font size to use for rendering tick labels.

axis_width : float

Line width for the axis

axis_label : str

Text to use for the axis label

axis_label_margin : float

Margin between ticks and axis labels

axis_font_size : float

The font size to use for rendering axis labels.

font_size : float

Font size for both the tick and axis labels. If this is set, tick_font_size and axis_font_size are ignored.

anchors : iterable

A 2-element iterable (tuple, list, etc.) giving the horizontal and vertical alignment of the tick labels. The first element should be one of ‘left’, ‘center’, or ‘right’, and the second element should be one of ‘bottom’, ‘middle’, or ‘top’. If this is not specified, it is determined automatically.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

class vispy.scene.visuals.Box(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.box.BoxVisual

Visual that displays a box.

This class inherits from visuals.BoxVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

width : float

Box width.

height : float

Box height.

depth : float

Box depth.

width_segments : int

Box segments count along the width.

height_segments : float

Box segments count along the height.

depth_segments : float

Box segments count along the depth.

planes: array_like

Any combination of {'-x', '+x', '-y', '+y', '-z', '+z'} Included planes in the box construction.

vertex_colors : ndarray

Same as for MeshVisual class. See create_plane for vertex ordering.

face_colors : ndarray

Same as for MeshVisual class. See create_plane for vertex ordering.

color : Color

The Color to use when drawing the cube faces.

edge_color : tuple or Color

The Color to use when drawing the cube edges. If None, then no cube edges are drawn.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

class vispy.scene.visuals.ColorBar(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.colorbar.ColorBarVisual

Visual subclass displaying a colorbar

This class inherits from visuals.ColorBarVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

cmap : str | vispy.color.ColorMap

Either the name of the ColorMap to be used from the standard set of names (refer to vispy.color.get_colormap), or a custom ColorMap object. The ColorMap is used to apply a gradient on the colorbar.

orientation : {‘left’, ‘right’, ‘top’, ‘bottom’}

The orientation of the colorbar, used for rendering. The orientation can be thought of as the position of the label relative to the color bar.

When the orientation is ‘left’ or ‘right’, the colorbar is vertically placed. When it is ‘top’ or ‘bottom’, the colorbar is horizontally placed.

  • ‘top’: the colorbar is horizontal. Color is applied from left to right. Minimum corresponds to left and maximum to right. Label is to the top of the colorbar
  • ‘bottom’: Same as top, except that label is to the bottom of the colorbar
  • ‘left’: the colorbar is vertical. Color is applied from bottom to top. Minimum corresponds to bottom and maximum to top. Label is to the left of the colorbar
  • ‘right’: Same as left, except that the label is placed to the right of the colorbar

size : (major_axis_length, minor_axis_length)

lengths with respect to the major and minor axes. The minor axis is the shorter axis, while the major axis is the longer axis with respect to the orientation

For orientations ‘top’ and ‘bottom’, the major axis is along the length.

For orientations ‘left’ and ‘right’, the major axis is along the breadth

pos : tuple (x, y)

Position where the colorbar is to be placed with respect to the center of the colorbar

label_str : str

The label that is to be drawn with the colorbar that provides information about the colorbar.

label_color : str | vispy.color.Color

The color of the labels. This can either be a str as the color’s name or an actual instace of a vipy.color.Color

clim : tuple (min, max)

the minimum and maximum values of the data that is given to the colorbar. This is used to draw the scale on the side of the colorbar.

border_width : float (in px)

The width of the border the colormap should have. This measurement is given in pixels

border_color : str | vispy.color.Color

The color of the border of the colormap. This can either be a str as the color’s name or an actual instace of a vipy.color.Color

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

class vispy.scene.visuals.Compound(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.visual.CompoundVisual

Visual consisting entirely of sub-visuals.

This class inherits from visuals.CompoundVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

To the user, a compound visual behaves exactly like a normal visual–it has a transform system, draw() and bounds() methods, etc. Internally, the compound visual automatically manages proxying these transforms and methods to its sub-visuals.

Parameters:

subvisuals : list of BaseVisual instances

The list of visuals to be combined in this compound visual.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

class vispy.scene.visuals.Cube(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.cube.CubeVisual

Visual that displays a cube or cuboid

This class inherits from visuals.CubeVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

size : float or tuple

The size of the cuboid. A float gives a cube, whereas tuples may specify the size of each axis (x, y, z) independently.

vertex_colors : ndarray

Same as for MeshVisual class. See create_cube for vertex ordering.

face_colors : ndarray

Same as for MeshVisual class. See create_cube for vertex ordering.

color : Color

The Color to use when drawing the cube faces.

edge_color : tuple or Color

The Color to use when drawing the cube edges. If None, then no cube edges are drawn.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

class vispy.scene.visuals.Ellipse(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.ellipse.EllipseVisual

Displays a 2D ellipse

This class inherits from visuals.EllipseVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

center : array

Center of the ellipse

color : instance of Color

The face color to use.

border_color : instance of Color

The border color to use.

border_width: float

The width of the border in pixels Line widths > 1px are only guaranteed to work when using border_method=’agg’ method.

radius : float | tuple

Radius or radii of the ellipse Defaults to (0.1, 0.1)

start_angle : float

Start angle of the ellipse in degrees Defaults to 0.

span_angle : float

Span angle of the ellipse in degrees Defaults to 360.

num_segments : int

Number of segments to be used to draw the ellipse Defaults to 100

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

**kwargs : dict

Keyword arguments to pass to PolygonVisual.

class vispy.scene.visuals.Graph(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.graphs.graph.GraphVisual

Visual for displaying graphs or networks.

This class inherits from visuals.GraphVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

adjacency_mat : array or sparse

The adjacency matrix of the graph.

directed : bool

Whether the graph is directed or not. If True, then this visual will draw arrows for the directed edges.

layout : str

They layout to use.

animate : bool

Whether or not to animate.

line_color : str or vispy.color.colormap.ColorMap

The color to use for the edges.

line_width : number

The edge thickness.

arrow_type : str

The kind of arrow head to use. See vispy.visuals.ArrowHead for more information.

arrow_size : number

The size of the arrow head.

node_symbol : string

The marker to use for nodes. See vispy.visuals.MarkersVisual for more information.

node_size : number

The size of the node

border_color : str or vispy.color.colormap.ColorMap

The border color for nodes.

face_color : str or vispy.color.colormap.ColorMap

The face color for nodes.

border_width : number

The border size for nodes.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

See also

ArrowVisual, MarkersVisual

class vispy.scene.visuals.GridLines(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.gridlines.GridLinesVisual

Displays regularly spaced grid lines in any coordinate system and at any scale.

This class inherits from visuals.GridLinesVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

scale : tuple

The scale factors to apply when determining the spacing of grid lines.

color : Color

The base color for grid lines. The final color may have its alpha channel modified.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

class vispy.scene.visuals.GridMesh(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.gridmesh.GridMeshVisual

Displays a mesh in a Cartesian grid about x,y,z coordinates.

This class inherits from visuals.GridMeshVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

This makes it simple to generate a mesh from e.g. the output of numpy.meshgrid.

All arguments are optional, though they can be changed individually later with the set_data method.

Parameters:

xs : ndarray

A 2d array of x coordinates for the vertices of the mesh. Must have the same dimensions as ys and zs.

ys : ndarray

A 2d array of y coordinates for the vertices of the mesh. Must have the same dimensions as xs and zs.

zs : ndarray

A 2d array of z coordinates for the vertices of the mesh. Must have the same dimensions as xs and ys.

colors : ndarray | None

The colors of the points of the mesh. Should be either a (width, height, 4) array of rgba colors at each grid point or a (width, height, 3) array of rgb colors at each grid point. Defaults to None, in which case the default color of a MeshVisual is used.

shading : str | None

Same as for the MeshVisual class. Defaults to ‘smooth’.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

**kwargs :

Other arguments are passed directly to MeshVisual.

class vispy.scene.visuals.Histogram(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.histogram.HistogramVisual

Visual that calculates and displays a histogram of data

This class inherits from visuals.HistogramVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

data : array-like

Data to histogram. Currently only 1D data is supported.

bins : int | array-like

Number of bins, or bin edges.

color : instance of Color

Color of the histogram.

orientation : {‘h’, ‘v’}

Orientation of the histogram.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

class vispy.scene.visuals.Image(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.image.ImageVisual

Visual subclass displaying an image.

This class inherits from visuals.ImageVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

data : ndarray

ImageVisual data. Can be shape (M, N), (M, N, 3), or (M, N, 4).

method : str

Selects method of rendering image in case of non-linear transforms. Each method produces similar results, but may trade efficiency and accuracy. If the transform is linear, this parameter is ignored and a single quad is drawn around the area of the image.

  • ‘auto’: Automatically select ‘impostor’ if the image is drawn with a nonlinear transform; otherwise select ‘subdivide’.
  • ‘subdivide’: ImageVisual is represented as a grid of triangles with texture coordinates linearly mapped.
  • ‘impostor’: ImageVisual is represented as a quad covering the entire view, with texture coordinates determined by the transform. This produces the best transformation results, but may be slow.

grid: tuple (rows, cols)

If method=’subdivide’, this tuple determines the number of rows and columns in the image grid.

cmap : str | ColorMap

Colormap to use for luminance images.

clim : str | tuple

Limits to use for the colormap. Can be ‘auto’ to auto-set bounds to the min and max of the data.

interpolation : str

Selects method of image interpolation. Makes use of the two Texture2D interpolation methods and the available interpolation methods defined in vispy/gloo/glsl/misc/spatial_filters.frag

  • ‘nearest’: Default, uses ‘nearest’ with Texture2D interpolation.
  • ‘bilinear’: uses ‘linear’ with Texture2D interpolation.
  • ‘hanning’, ‘hamming’, ‘hermite’, ‘kaiser’, ‘quadric’, ‘bicubic’,
    ‘catrom’, ‘mitchell’, ‘spline16’, ‘spline36’, ‘gaussian’, ‘bessel’, ‘sinc’, ‘lanczos’, ‘blackman’

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

**kwargs : dict

Keyword arguments to pass to Visual.

Notes

The colormap functionality through cmap and clim are only used if the data are 2D.

class vispy.scene.visuals.InfiniteLine(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.infinite_line.InfiniteLineVisual

Infinite horizontal or vertical line for 2D plots.

This class inherits from visuals.InfiniteLineVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

pos : float

Position of the line along the axis.

color : list, tuple, or array

The color to use when drawing the line. If an array is given, it must be of shape (1, 4) and provide one rgba color per vertex.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

vertical:

True for drawing a vertical line, False for an horizontal line

class vispy.scene.visuals.Isocurve(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.isocurve.IsocurveVisual

Displays an isocurve of a 2D scalar array.

This class inherits from visuals.IsocurveVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

data : ndarray | None

2D scalar array.

levels : ndarray, shape (Nlev,) | None

The levels at which the isocurve is constructed from “data”.

color_lev : Color, colormap name, tuple, list or array

The color to use when drawing the line. If a list is given, it must be of shape (Nlev), if an array is given, it must be of shape (Nlev, …). and provide one color per level (rgba, colorname).

clim : tuple

(min, max) limits to apply when mapping level values through a colormap.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

**kwargs : dict

Keyword arguments to pass to LineVisual.

class vispy.scene.visuals.Isoline(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.isoline.IsolineVisual

Isocurves of a tri mesh with data at vertices at different levels.

This class inherits from visuals.IsolineVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

vertices : ndarray, shape (Nv, 3) | None

Vertex coordinates.

tris : ndarray, shape (Nf, 3) | None

Indices into the vertex array.

data : ndarray, shape (Nv,) | None

scalar at vertices

levels : ndarray, shape (Nlev,) | None

The levels at which the isocurve is constructed from “data”.

color_lev : Color, tuple, colormap name or array

The color to use when drawing the line. If an array is given, it must be of shape (Nlev, 4) and provide one rgba color by level.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

**kwargs : dict

Keyword arguments to pass to LineVisual.

class vispy.scene.visuals.Isosurface(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.isosurface.IsosurfaceVisual

Displays an isosurface of a 3D scalar array.

This class inherits from visuals.IsosurfaceVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

data : ndarray | None

3D scalar array.

level: float | None

The level at which the isosurface is constructed from data.

vertex_colors : ndarray | None

The vertex colors to use.

face_colors : ndarray | None

The face colors to use.

color : ndarray | None

The color to use.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

**kwargs : dict

Keyword arguments to pass to the mesh construction.

class vispy.scene.visuals.Line(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.line.line.LineVisual

Line visual

This class inherits from visuals.LineVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

pos : array

Array of shape (…, 2) or (…, 3) specifying vertex coordinates.

color : Color, tuple, or array

The color to use when drawing the line. If an array is given, it must be of shape (…, 4) and provide one rgba color per vertex. Can also be a colormap name, or appropriate Function.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

width:

The width of the line in px. Line widths > 1px are only guaranteed to work when using ‘agg’ method.

connect : str or array

Determines which vertices are connected by lines.

  • “strip” causes the line to be drawn with each vertex connected to the next.
  • “segments” causes each pair of vertices to draw an independent line segment
  • numpy arrays specify the exact set of segment pairs to connect.

method : str

Mode to use for drawing.

  • “agg” uses anti-grain geometry to draw nicely antialiased lines with proper joins and endcaps.
  • “gl” uses OpenGL’s built-in line rendering. This is much faster, but produces much lower-quality results and is not guaranteed to obey the requested line width or join/endcap styles.

antialias : bool

Enables or disables antialiasing. For method=’gl’, this specifies whether to use GL’s line smoothing, which may be unavailable or inconsistent on some platforms.

class vispy.scene.visuals.LinearRegion(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.linear_region.LinearRegionVisual

Infinite horizontal or vertical region for 2D plots.

This class inherits from visuals.LinearRegionVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

pos : list, tuple or numpy array

Bounds of the region along the axis. len(pos) must be >=2.

color : list, tuple, or array

The color to use when drawing the line. It must have a shape of (1, 4) for a single color region or (len(pos), 4) for a multicolor region.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

vertical:

True for drawing a vertical region, False for an horizontal region

class vispy.scene.visuals.LinePlot(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.line_plot.LinePlotVisual

Visual displaying a plot line with optional markers.

This class inherits from visuals.LinePlotVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

data : array-like

Arguments can be passed as (Y,), (X, Y), (X, Y, Z) or np.array((X, Y)), np.array((X, Y, Z)).

color : instance of Color

Color of the line.

symbol : str

Marker symbol to use.

line_kind : str

Kind of line to draw. For now, only solid lines ('-') are supported.

width : float

Line width.

marker_size : float

Marker size. If size == 0 markers will not be shown.

edge_color : instance of Color

Color of the marker edge.

face_color : instance of Color

Color of the marker face.

edge_width : float

Edge width of the marker.

connect : str | array

See LineVisual.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

**kwargs : keyword arguments

Argements to pass to the super class.

See also

LineVisual, MarkersVisual, marker_types

Examples

All of these syntaxes will work:

>>> LinePlotVisual(y_vals)
>>> LinePlotVisual(x_vals, y_vals)
>>> LinePlotVisual(xy_vals)
class vispy.scene.visuals.Markers(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.markers.MarkersVisual

Visual displaying marker symbols.

This class inherits from visuals.MarkersVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

class vispy.scene.visuals.Mesh(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.mesh.MeshVisual

Mesh visual

This class inherits from visuals.MeshVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

vertices : array-like | None

The vertices.

faces : array-like | None

The faces.

vertex_colors : array-like | None

Colors to use for each vertex.

face_colors : array-like | None

Colors to use for each face.

color : instance of Color

The color to use.

vertex_values : array-like | None

The values to use for each vertex (for colormapping).

meshdata : instance of MeshData | None

The meshdata.

shading : str | None

Shading to use.

mode : str

The drawing mode.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

**kwargs : dict

Keyword arguments to pass to Visual.

class vispy.scene.visuals.Plane(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.plane.PlaneVisual

Visual that displays a plane.

This class inherits from visuals.PlaneVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

width : float

Plane width.

height : float

Plane height.

width_segments : int

Plane segments count along the width.

height_segments : float

Plane segments count along the height.

direction: unicode

{'-x', '+x', '-y', '+y', '-z', '+z'} Direction the plane will be facing.

vertex_colors : ndarray

Same as for MeshVisual class. See create_plane for vertex ordering.

face_colors : ndarray

Same as for MeshVisual class. See create_plane for vertex ordering.

color : Color

The Color to use when drawing the cube faces.

edge_color : tuple or Color

The Color to use when drawing the cube edges. If None, then no cube edges are drawn.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

class vispy.scene.visuals.Polygon(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.polygon.PolygonVisual

Displays a 2D polygon

This class inherits from visuals.PolygonVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

pos : array

Set of vertices defining the polygon.

color : str | tuple | list of colors

Fill color of the polygon.

border_color : str | tuple | list of colors

Border color of the polygon.

border_width : int

Border width in pixels. Line widths > 1px are only guaranteed to work when using border_method=’agg’ method.

border_method : str

Mode to use for drawing the border line (see LineVisual).

  • “agg” uses anti-grain geometry to draw nicely antialiased lines with proper joins and endcaps.
  • “gl” uses OpenGL’s built-in line rendering. This is much faster, but produces much lower-quality results and is not guaranteed to obey the requested line width or join/endcap styles.

triangulate : boolean

Triangulate the set of vertices

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

**kwargs : dict

Keyword arguments to pass to CompoundVisual.

class vispy.scene.visuals.Rectangle(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.rectangle.RectangleVisual

Displays a 2D rectangle with optional rounded corners

This class inherits from visuals.RectangleVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

center : array

Center of the rectangle

color : instance of Color

The fill color to use.

border_color : instance of Color

The border color to use.

border_width : int

Border width in pixels. Line widths > 1px are only guaranteed to work when using border_method=’agg’ method.

height : float

Length of the rectangle along y-axis Defaults to 1.0

width : float

Length of the rectangle along x-axis Defaults to 1.0

radius : float | array

Radii of curvatures of corners in clockwise order from top-left Defaults to 0.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

**kwargs : dict

Keyword arguments to pass to PolygonVisual.

class vispy.scene.visuals.RegularPolygon(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.regular_polygon.RegularPolygonVisual

Displays a regular polygon

This class inherits from visuals.RegularPolygonVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

center : array-like (x, y)

Center of the regular polygon

color : str | tuple | list of colors

Fill color of the polygon

border_color : str | tuple | list of colors

Border color of the polygon

border_width: float

The width of the border in pixels

radius : float

Radius of the regular polygon Defaults to 0.1

sides : int

Number of sides of the regular polygon

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

class vispy.scene.visuals.ScrollingLines(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.scrolling_lines.ScrollingLinesVisual

Displays many line strips of equal length, with the option to add new vertex data to one end of the lines.

This class inherits from visuals.ScrollingLinesVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

n_lines : int

The number of independent line strips to draw.

line_size : int

The number of samples in each line strip.

dx : float

The x distance between samples

color : array-like

An array of colors to assign to each line strip.

pos_offset : array-like

An array of x, y position offsets to apply to each line strip.

columns : int

Arrange line strips into a grid with this number of columns. This option is not compatible with pos_offset.

cell_size : tuple

The x, y distance between cells in the grid.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

class vispy.scene.visuals.Spectrogram(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.spectrogram.SpectrogramVisual

Calculate and show a spectrogram

This class inherits from visuals.SpectrogramVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

x : array-like

1D signal to operate on. If len(x) < n_fft, x will be zero-padded to length n_fft.

n_fft : int

Number of FFT points. Much faster for powers of two.

step : int | None

Step size between calculations. If None, n_fft // 2 will be used.

fs : float

The sample rate of the data.

window : str | None

Window function to use. Can be 'hann' for Hann window, or None for no windowing.

color_scale : {‘linear’, ‘log’}

Scale to apply to the result of the STFT. 'log' will use 10 * log10(power).

cmap : str

Colormap name.

clim : str | tuple

Colormap limits. Should be 'auto' or a two-element tuple of min and max values.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

class vispy.scene.visuals.Sphere(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.sphere.SphereVisual

Visual that displays a sphere

This class inherits from visuals.SphereVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

radius : float

The size of the sphere.

cols : int

Number of cols that make up the sphere mesh (for method=’latitude’ and ‘cube’).

rows : int

Number of rows that make up the sphere mesh (for method=’latitude’ and ‘cube’).

depth : int

Number of depth segments that make up the sphere mesh (for method=’cube’).

subdivisions : int

Number of subdivisions to perform (for method=’ico’).

method : str

Method for generating sphere. Accepts ‘latitude’ for latitude-longitude, ‘ico’ for icosahedron, and ‘cube’ for cube based tessellation.

vertex_colors : ndarray

Same as for MeshVisual class. See create_sphere for vertex ordering.

face_colors : ndarray

Same as for MeshVisual class. See create_sphere for vertex ordering.

color : Color

The Color to use when drawing the sphere faces.

edge_color : tuple or Color

The Color to use when drawing the sphere edges. If None, then no sphere edges are drawn.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

class vispy.scene.visuals.SurfacePlot(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.surface_plot.SurfacePlotVisual

Displays a surface plot on a regular x,y grid

This class inherits from visuals.SurfacePlotVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

x : ndarray | None

1D array of values specifying the x positions of vertices in the grid. If None, values will be assumed to be integers.

y : ndarray | None

1D array of values specifying the x positions of vertices in the grid. If None, values will be assumed to be integers.

z : ndarray

2D array of height values for each grid vertex.

colors : ndarray

(width, height, 4) array of vertex colors.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

Notes

All arguments are optional.

Note that if vertex positions are updated, the normal vectors for each triangle must be recomputed. This is somewhat expensive if the surface was initialized with smooth=False and very expensive if smooth=True. For faster performance, initialize with compute_normals=False and use per-vertex colors or a material that does not require normals.

class vispy.scene.visuals.Text(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.text.text.TextVisual

Visual that displays text

This class inherits from visuals.TextVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

text : str | list of str

Text to display. Can also be a list of strings. Note: support for list of str might be removed soon in favor of text collections.

color : instance of Color

Color to use.

bold : bool

Bold face.

italic : bool

Italic face.

face : str

Font face to use.

font_size : float

Point size to use.

pos : tuple | list of tuple

Position (x, y) or (x, y, z) of the text. Can also be a list of tuple if text is a list.

rotation : float

Rotation (in degrees) of the text clockwise.

anchor_x : str

Horizontal text anchor.

anchor_y : str

Vertical text anchor.

font_manager : object | None

Font manager to use (can be shared if the GLContext is shared).

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

class vispy.scene.visuals.Tube(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.tube.TubeVisual

Displays a tube around a piecewise-linear path.

This class inherits from visuals.TubeVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

The tube mesh is corrected following its Frenet curvature and torsion such that it varies smoothly along the curve, including if the tube is closed.

Parameters:

points : ndarray

An array of (x, y, z) points describing the path along which the tube will be extruded.

radius : float

The radius of the tube. Defaults to 1.0.

closed : bool

Whether the tube should be closed, joining the last point to the first. Defaults to False.

color : Color | ColorArray

The color(s) to use when drawing the tube. The same color is applied to each vertex of the mesh surrounding each point of the line. If the input is a ColorArray, the argument will be cycled; for instance if ‘red’ is passed then the entire tube will be red, or if [‘green’, ‘blue’] is passed then the points will alternate between these colours. Defaults to ‘purple’.

tube_points : int

The number of points in the circle-approximating polygon of the tube’s cross section. Defaults to 8.

shading : str | None

Same as for the MeshVisual class. Defaults to ‘smooth’.

vertex_colors: ndarray | None

Same as for the MeshVisual class.

face_colors: ndarray | None

Same as for the MeshVisual class.

mode : str

Same as for the MeshVisual class. Defaults to ‘triangles’.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

class vispy.scene.visuals.Volume(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.volume.VolumeVisual

Displays a 3D Volume

This class inherits from visuals.VolumeVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

vol : ndarray

The volume to display. Must be ndim==3.

clim : tuple of two floats | None

The contrast limits. The values in the volume are mapped to black and white corresponding to these values. Default maps between min and max.

method : {‘mip’, ‘translucent’, ‘additive’, ‘iso’}

The render method to use. See corresponding docs for details. Default ‘mip’.

threshold : float

The threshold to use for the isosurface render method. By default the mean of the given volume is used.

relative_step_size : float

The relative step size to step through the volume. Default 0.8. Increase to e.g. 1.5 to increase performance, at the cost of quality.

cmap : str

Colormap to use.

emulate_texture : bool

Use 2D textures to emulate a 3D texture. OpenGL ES 2.0 compatible, but has lower performance on desktop platforms.

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).

class vispy.scene.visuals.XYZAxis(*args, **kwargs)[source]

Bases: vispy.scene.visuals.VisualNode, vispy.visuals.xyz_axis.XYZAxisVisual

Simple 3D axis for indicating coordinate system orientation. Axes are x=red, y=green, z=blue.

This class inherits from visuals.XYZAxisVisual and scene.Node, allowing the visual to be placed inside a scenegraph.

Parameters:

parent : Node

The parent node to assign to this node (optional).

name : string

A name for this node, used primarily for debugging (optional).


vispy.scene.widgets

The vispy.scene.widgets namespace provides a range of widgets to allow user interaction. Widgets are rectangular Visual objects such as buttons and sliders.

class vispy.scene.widgets.AxisWidget(orientation='left', **kwargs)[source]

Bases: vispy.scene.widgets.widget.Widget

Widget containing an axis

Parameters:

orientation : str

Orientation of the axis, ‘left’ or ‘bottom’.

**kwargs : dict

Keyword arguments to pass to AxisVisual.

Link this axis to a ViewBox

This makes it so that the axis’s domain always matches the visible range in the ViewBox.

Parameters:

view : instance of ViewBox

The ViewBox to link.

on_resize(event)[source]

Resize event handler

Parameters:

event : instance of Event

The event.

class vispy.scene.widgets.Console(text_color='black', font_size=12.0, **kwargs)[source]

Bases: vispy.scene.widgets.widget.Widget

Fast and failsafe text console

Parameters:

text_color : instance of Color

Color to use.

font_size : float

Point size to use.

clear()[source]

Clear the console

font_size

The font size (in points) of the text

on_resize(event)[source]

Resize event handler

Parameters:

event : instance of Event

The event.

text_color

The color of the text

write(text='', wrap=True)[source]

Write text and scroll

Parameters:

text : str

Text to write. '' can be used for a blank line, as a newline is automatically added to the end of each line.

wrap : str

If True, long messages will be wrapped to span multiple lines.

class vispy.scene.widgets.ColorBarWidget(cmap, orientation, label='', label_color='black', clim=('', ''), border_width=0.0, border_color='black', padding=(0.2, 0.2), axis_ratio=0.05, **kwargs)[source]

Bases: vispy.scene.widgets.widget.Widget

Widget containing a ColorBar

Parameters:

cmap : str | vispy.color.ColorMap

Either the name of the ColorMap to be used from the standard set of names (refer to vispy.color.get_colormap), or a custom ColorMap object. The ColorMap is used to apply a gradient on the colorbar.

orientation : {‘left’, ‘right’, ‘top’, ‘bottom’}

The orientation of the colorbar, used for rendering. The orientation can be thought of as the position of the label relative to the color bar.

When the orientation is ‘left’ or ‘right’, the colorbar is vertically placed. When it is ‘top’ or ‘bottom’, the colorbar is horizontally placed. The colorbar automatically resizes when its container’s dimension changes.

  • ‘top’: the colorbar is horizontal. Color is applied from left to right. Minimum corresponds to left and maximum to right. Label is to the top of the colorbar
  • ‘bottom’: Same as top, except that label is to the bottom of the colorbar
  • ‘left’: the colorbar is vertical. Color is applied from bottom to top. Minimum corresponds to bottom and maximum to top. Label is to the left of the colorbar
  • ‘right’: Same as left, except that the label is placed to the right of the colorbar

label : str

The label that is to be drawn with the colorbar that provides information about the colorbar.

label_color : str | vispy.color.Color

The color of labels. This can either be a str as the color’s name or an actual instace of a vipy.color.Color

clim : tuple (min, max)

the minimum and maximum values of the data that is given to the colorbar. This is used to draw the scale on the side of the colorbar.

border_width : float (in px)

The width of the border the colormap should have. This measurement is given in pixels

border_color : str | vispy.color.Color

The color of the border of the colormap. This can either be a str as the color’s name or an actual instace of a vipy.color.Color

padding : tuple (major_axis, minor_axis) [0, 1]

padding with respect to the major and minor axis

axis_ratio : float

ratio of minor axis to major axis

border_color

The color of the border around the ColorBar in pixels

border_width

The width of the border around the ColorBar in pixels

on_resize(event)[source]

Resize event handler

Parameters:

event : instance of Event

The event.

class vispy.scene.widgets.Grid(spacing=6, **kwargs)[source]

Bases: vispy.scene.widgets.widget.Widget

Widget that automatically sets the position and size of child Widgets to proportionally divide its internal area into a grid.

Parameters:

spacing : int

Spacing between widgets.

**kwargs : dict

Keyword arguments to pass to Widget.

add_grid(row=None, col=None, row_span=1, col_span=1, **kwargs)[source]

Create a new Grid and add it as a child widget.

Parameters:

row : int

The row in which to add the widget (0 is the topmost row)

col : int

The column in which to add the widget (0 is the leftmost column)

row_span : int

The number of rows to be occupied by this widget. Default is 1.

col_span : int

The number of columns to be occupied by this widget. Default is 1.

**kwargs : dict

Keyword arguments to pass to the new Grid.

add_view(row=None, col=None, row_span=1, col_span=1, **kwargs)[source]

Create a new ViewBox and add it as a child widget.

Parameters:

row : int

The row in which to add the widget (0 is the topmost row)

col : int

The column in which to add the widget (0 is the leftmost column)

row_span : int

The number of rows to be occupied by this widget. Default is 1.

col_span : int

The number of columns to be occupied by this widget. Default is 1.

**kwargs : dict

Keyword arguments to pass to ViewBox.

add_widget(widget=None, row=None, col=None, row_span=1, col_span=1, **kwargs)[source]

Add a new widget to this grid. This will cause other widgets in the grid to be resized to make room for the new widget. Can be used to replace a widget as well

Parameters:

widget : Widget | None

The Widget to add. New widget is constructed if widget is None.

row : int

The row in which to add the widget (0 is the topmost row)

col : int

The column in which to add the widget (0 is the leftmost column)

row_span : int

The number of rows to be occupied by this widget. Default is 1.

col_span : int

The number of columns to be occupied by this widget. Default is 1.

**kwargs : dict

parameters sent to the new Widget that is constructed if widget is None

Notes

The widget’s parent is automatically set to this grid, and all other parent(s) are removed.

remove_widget(widget)[source]

Remove a widget from this grid

Parameters:

widget : Widget

The Widget to remove

resize_widget(widget, row_span, col_span)[source]

Resize a widget in the grid to new dimensions.

Parameters:

widget : Widget

The widget to resize

row_span : int

The number of rows to be occupied by this widget.

col_span : int

The number of columns to be occupied by this widget.

class vispy.scene.widgets.Label(text, rotation=0.0, **kwargs)[source]

Bases: vispy.scene.widgets.widget.Widget

Label widget

Parameters:

text : str

The label.

rotation : float

The rotation of the label.

**kwargs : dict

Keyword arguments to pass to TextVisual.

on_resize(event)[source]

Resize event handler

Parameters:

event : instance of Event

The event.

class vispy.scene.widgets.ViewBox(camera=None, **kwargs)[source]

Bases: vispy.scene.widgets.widget.Widget

Provides a rectangular widget to which its subscene is rendered.

Three classes work together when using a ViewBox: * The SubScene class describes a “world” coordinate system and the entities that live inside it. * ViewBox is a “window” through which we view the subscene. Multiple ViewBoxes may view the same subscene. * Camera describes both the perspective from which the subscene is rendered, and the way user interaction affects that perspective.

In general it is only necessary to create the ViewBox; a SubScene and Camera will be generated automatically.

Parameters:

camera : instance of Camera | str | None

The camera through which to view the SubScene. If None, then a PanZoomCamera (2D interaction) is used. If str, then the string is used as the argument to make_camera().

**kwargs : dict

Extra keyword arguments to pass to Widget.

add(node)[source]

Add an Node to the scene for this ViewBox.

This is a convenience method equivalent to node.parent = viewbox.scene

Parameters:

node : instance of Node

The node to add.

camera

Get/set the Camera in use by this ViewBox

If a string is given (e.g. ‘panzoom’, ‘turntable’, ‘fly’). A corresponding camera is selected if it already exists in the scene, otherwise a new camera is created.

The camera object is made a child of the scene (if it is not already in the scene).

Multiple cameras can exist in one scene, although only one can be active at a time. A single camera can be used by multiple viewboxes at the same time.

get_scene_bounds(dim=None)[source]

Get the total bounds based on the visuals present in the scene

Parameters:

dim : int | None

Dimension to return.

Returns:

bounds : list | tuple

If dim is None, Returns a list of 3 tuples, otherwise the bounds for the requested dimension.

is_in_scene(node)[source]

Get whether the given node is inside the scene of this viewbox.

Parameters:

node : instance of Node

The node.

on_resize(event)[source]

Resize event handler

Parameters:

event : instance of Event

The event.

scene

The root node of the scene viewed by this ViewBox.

class vispy.scene.widgets.Widget(pos=(0, 0), size=(10, 10), border_color=None, border_width=1, bgcolor=None, padding=0, margin=0, **kwargs)[source]

Bases: vispy.scene.visuals.Compound

A widget takes up a rectangular space, intended for use in a 2D pixel coordinate frame.

The widget is positioned using the transform attribute (as any node), and its extent (size) is kept as a separate property.

Parameters:

pos : (x, y)

A 2-element tuple to specify the top left corner of the widget.

size : (w, h)

A 2-element tuple to spicify the size of the widget.

border_color : color

The color of the border.

border_width : float

The width of the border line in pixels.

bgcolor : color

The background color.

padding : int

The amount of padding in the widget (i.e. the space reserved between the contents and the border).

margin : int

The margin to keep outside the widget’s border.

add_grid(*args, **kwargs)[source]

Create a new Grid and add it as a child widget.

All arguments are given to Grid().

add_view(*args, **kwargs)[source]

Create a new ViewBox and add it as a child widget.

All arguments are given to ViewBox().

add_widget(widget)[source]

Add a Widget as a managed child of this Widget.

The child will be automatically positioned and sized to fill the entire space inside this Widget (unless _update_child_widgets is redefined).

Parameters:

widget : instance of Widget

The widget to add.

Returns:

widget : instance of Widget

The widget.

bgcolor

The background color of the Widget.

border_color

The color of the border.

height

The actual height of the widget

height_max

The maximum height of the widget

height_min

The minimum height of the widget

inner_rect

The rectangular area inside the margin, border, and padding.

Generally widgets should avoid drawing or placing sub-widgets outside this rectangle.

remove_widget(widget)[source]

Remove a Widget as a managed child of this Widget.

Parameters:

widget : instance of Widget

The widget to remove.

size

The size (w, h) of this widget.

If the widget is a child of another widget, then its size is assigned automatically by its parent.

stretch

Stretch factors (w, h) used when determining how much space to allocate to this widget in a layout.

If either stretch factor is None, then it will be assigned when the widget is added to a layout based on the number of columns or rows it occupies.

width

The actual width of this widget

width_max

The maximum width the widget can have

width_min

The minimum width the widget can have