The vispy native plotting module

This module provides functions for displaying data from a command-line interface.

NOTE: This module is still experimental, and under development. It currently lacks axes, but that is a high-priority target for the next release.


To use vispy.plot typically the main class Fig is first instantiated:

>>> from vispy.plot import Fig
>>> fig = Fig()

And then PlotWidget instances are automatically created by accessing the fig instance:

>>> ax_left = fig[0, 0]
>>> ax_right = fig[0, 1]

Then plots are accomplished via methods of the PlotWidget instances:

>>> import numpy as np
>>> data = np.random.randn(2, 10)
>>> ax_left.plot(data)
>>> ax_right.histogram(data[1])
class vispy.plot.Fig(bgcolor='w', size=(800, 600), show=True)

Create a figure window


bgcolor : instance of Color

Color to use for the background.

size : tuple

Size of the figure window in pixels.

show : bool

If True, show the window.

See also

the axis widget for plotting
the super class


You can create a Figure, PlotWidget, and diagonal line plot like this:

>>> from vispy.plot import Fig
>>> fig = Fig()
>>> ax = fig[0, 0]  # this creates a PlotWidget
>>> ax.plot([[0, 1], [0, 1]])

See the gallery for many other examples.


close() Close the canvas
connect(fun) Connect a function to an event
create_native() Create the native widget if not already done so.
draw_visual(visual[, event, viewport]) Draw a visual to the canvas or currently active framebuffer.
measure_fps([window, callback]) Measure the current FPS
on_draw(event) Draw handler
on_resize(event) Resize handler
pop_fbo() Pop an FBO from the stack.
pop_viewport() Pop a viewport from the stack.
push_fbo(fbo, offset, csize) Push an FBO on the stack, together with the new viewport.
push_viewport(viewport) Push a viewport on the stack
render([region, size]) Render the scene to an offscreen buffer and return the image array.
set_current([event]) Make this the active GL canvas
show([visible, run]) Show or hide the canvas
swap_buffers([event]) Swap GL buffers such that the offscreen buffer becomes visible
update([event]) Inform the backend that the Canvas needs to be redrawn

List of the associated PlotWidget instances

class vispy.plot.PlotWidget(*args, **kwargs)

Widget to facilitate plotting


*args : arguments

Arguments passed to the ViewBox super class.

**kwargs : keywoard arguments

Keyword arguments passed to the ViewBox super class.


This class is typically instantiated implicitly by a Figure instance, e.g., by doing fig[0, 0].


add(node) Add an Node to the scene for this ViewBox.
add_grid(*args, **kwargs) Create a new Grid and add it as a child widget.
add_parent(parent) Add a parent
add_view(*args, **kwargs) Create a new ViewBox and add it as a child widget.
add_widget(widget) Add a Widget as a managed child of this Widget.
common_parent(node) Return the common parent of two entities
describe_tree([with_transform]) Create tree diagram of children
draw(event) Draw the viewbox border/background
get_scene_bounds([dim]) Get the total bounds based on the visuals present in the scene
histogram(data[, bins, color, orientation]) Calculate and show a histogram of data
image(data[, cmap, clim]) Show an image
is_in_scene(node) Get whether the given node is inside the scene of this viewbox.
mesh([vertices, faces, vertex_colors, ...]) Show a 3D mesh
node_path(node) Return two lists describing the path from this node to another
node_path_to_child(node) Return a list describing the path from this node to a child node
node_path_transforms(node) Return the list of transforms along the path to another node.
node_transform(node) Return the transform that maps from the coordinate system of self to the local coordinate system of node.
on_resize(event) On resize handler
plot(data[, color, symbol, line_kind, ...]) Plot a series of data using lines and markers
remove_parent(parent) Remove a parent
remove_widget(widget) Remove a Widget as a managed child of this Widget.
set_transform(type_, *args, **kwargs) Create a new transform of type and assign it to this node.
spectrogram(x[, n_fft, step, fs, window, ...]) Calculate and show a spectrogram
update() Emit an event to inform listeners that properties of this Node or its children have changed.
volume(vol[, clim, method, threshold, cmap]) Show a 3D volume
histogram(data, bins=10, color='w', orientation='h')

Calculate and show a histogram of data


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.


hist : instance of Polygon

The histogram polygon.

image(data, cmap='cubehelix', clim='auto')

Show an image


data : ndarray

Should have shape (N, M), (N, M, 3) or (N, M, 4).

cmap : str

Colormap name.

clim : str | tuple

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


image : instance of Image

The image.


The colormap is only used if the image pixels are scalars.

mesh(vertices=None, faces=None, vertex_colors=None, face_colors=None, color=(0.5, 0.5, 1.0), fname=None, meshdata=None)

Show a 3D mesh


vertices : array


faces : array | None

Face definitions.

vertex_colors : array | None

Vertex colors.

face_colors : array | None

Face colors.

color : instance of Color

Color to use.

fname : str | None

Filename to load. If not None, then vertices, faces, and meshdata must be None.

meshdata : MeshData | None

Meshdata to use. If not None, then vertices, faces, and fname must be None.


mesh : instance of Mesh

The mesh.

plot(data, color='k', symbol='o', line_kind='-', width=1.0, marker_size=0.0, edge_color='k', face_color='k', edge_width=1.0)

Plot a series of data using lines and markers


data : array | two arrays

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

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.


line : instance of LinePlot

The line plot.

See also

marker_types, LinePlot

spectrogram(x, n_fft=256, step=None, fs=1.0, window='hann', color_scale='log', cmap='cubehelix', clim='auto')

Calculate and show a spectrogram


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.


spec : instance of Spectrogram

The spectrogram.

See also


volume(vol, clim=None, method='mip', threshold=None, cmap='grays')

Show a 3D volume


vol : ndarray

Volume to render.

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', 'iso', 'translucent', 'additive'}

The render style to use. See corresponding docs for details. Default 'mip'.

threshold : float

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

cmap : str

The colormap to use.


volume : instance of Volume

The volume visualization.

See also