class visbrain.objects.HypnogramObj(name, data=None, time=None, datafile=None, art=-1, wake=0, n1=1, n2=2, n3=3, rem=4, art_visual=1, wake_visual=0, rem_visual=-1, n1_visual=-2, n2_visual=-3, n3_visual=-4, art_color='#8bbf56', wake_color='#56bf8b', rem_color='#bf5656', n1_color='#aabcce', n2_color='#405c79', n3_color='#0b1c2c', line_width=2.0, antialias=False, unicolor=False, transform=None, parent=None, verbose=None, **kw)[source][source]

Hypnogram object.

name : string

Name of the hypnogram object or path to a *.txt or *.csv file.

data : array_like

Array of data of shape (n_pts,).

time : array_like | None

Array of time points of shape (n_pts,)

datafile : string | None

Path to the data file.

art, wake, rem, n1, n2, n3 :

Stage identification inside the data array.

art_visual, wake_visual, rem_visual, n1_visual, n2_visual, n3_visual :

Stage order when plotting.

art_color, wake_color, rem_color, n1_color, n2_color, n3_color :

Stage color.

line_width : float | 2.

Line with of the hypnogram.

antialias : bool | False

Use anti-aliasing line.

unicolor : bool | False

Use a uni black color for the hypnogram.

transform : VisPy.visuals.transforms | None

VisPy transformation to set to the parent node.

parent : VisPy.parent | None

Hypnogram object parent.

verbose : string

Verbosity level.

kw : dict | {}

Optional arguments are used to control the colorbar (See ColorbarObj).


List of supported shortcuts :

  • s : save the figure
  • <delete> : reset camera


>>> import numpy as np
>>> from visbrain.objects import HypnogramObj
>>> data = np.repeat(np.arange(6), 100) - 1.
>>> h_obj = HypnogramObj('hypno', data)
>>> h_obj.preview(axis=True)


__init__(name[, data, time, datafile, art, …]) Init.
animate([step, interval, iterations]) Animate the object.
copy() Get a copy of the object.
describe_tree() Tree description.
preview([bgcolor, axis, xyz, show, obj, …]) Previsualize the result.
record_animation(name[, n_pic, bgcolor]) Record an animated object and save as a *.gif file.
render() Render the canvas.
screenshot(saveas[, print_size, dpi, unit, …]) Take a screeshot of the scene.
set_shortcuts_to_canvas(canvas) Set shortcuts to a VisbrainCanvas.
set_stage(stage, idx_start, idx_end) Set stage.
to_dict() Return a dictionary of all colorbar args.
to_kwargs([addisminmax]) Return a dictionary for input arguments.
update() Fonction to run when an update is needed.
update_from_dict(kwargs) Update attributes from a dictionary.
animate(step=1.0, interval='auto', iterations=-1)[source]

Animate the object.

Note that this method can only be used with 3D objects.

step : float | 1.

Rotation step.

interval : float | ‘auto’

Time between events in seconds. The default is ‘auto’, which attempts to find the interval that matches the refresh rate of the current monitor. Currently this is simply 1/60.

iterations : int | -1

Number of iterations. Can be -1 for infinite.


Get the cmap value.


Get a copy of the object.


Get the data_folder value.


Get the line_width value.


Get the name value.


Get the parent value.

preview(bgcolor='black', axis=False, xyz=False, show=True, obj=None, size=(1200, 800), mpl=False, **kwargs)[source]

Previsualize the result.

bgcolor : array_like/string/tuple | ‘black’

Background color for the preview.

axis : bool | False

Add x and y axis with ticks.

xyz : bool | False

Add an (x, y, z) axis to the scene.

obj : VisbrainObj | None

Pass a Visbrain object if you want to use the camera of an other object.

size : tuple | (1200, 800)

Default size of the window.

mpl : bool | False

Use Matplotlib to display the object. This result in a non interactive figure.

kwargs : dict | {}

Optional arguments are passed to the VisbrainCanvas class.

record_animation(name, n_pic=10, bgcolor=None)[source]

Record an animated object and save as a *.gif file.

Note that this method :

  • Can only be used with 3D objects.
  • Requires the python package imageio
name : string

Name of the gif file (e.g ‘myfile.gif’)

n_pic : int | 10

Number of pictures to use to render the gif.

bgcolor : string, tuple, list | None

Background color.


Render the canvas.

img : array_like

Array of shape (n_rows, n_columns, 4) where 4 describes the RGBA components.

screenshot(saveas, print_size=None, dpi=300.0, unit='centimeter', factor=None, region=None, autocrop=False, bgcolor=None, transparent=False, obj=None, line_width=1.0, **kwargs)[source]

Take a screeshot of the scene.

By default, the rendered canvas will have the size of your screen. The screenshot() method provides two ways to increase to exported image resolution :

  • Using print_size, unit and dpi inputs : specify the size of the image at a specific dpi level. For example, you might want to have an (10cm, 15cm) image at 300 dpi.
  • Using the factor input : multiply the default image size by this factor. For example, if you have a (1920, 1080) monitor and if factor is 2, the exported image should have a shape of (3840, 2160) pixels.
saveas : str

The name of the file to be saved. This file must contains a extension like .png, .tiff, .jpg…

print_size : tuple | None

The desired print size. This argument should be used in association with the dpi and unit inputs. print_size describe should be a tuple of two floats describing (width, height) of the exported image for a specific dpi level. The final image might not have the exact desired size but will try instead to find a compromize regarding to the proportion of width/height of the original image.

dpi : float | 300.

Dots per inch for printing the image.

unit : {‘centimeter’, ‘millimeter’, ‘pixel’, ‘inch’}

Unit of the printed size.

factor : float | None

If you don’t want to use the print_size input, factor simply multiply the resolution of your screen.

region : tuple | None

Select a specific region. Must be a tuple of four integers each one describing (x_start, y_start, width, height).

autocrop : bool | False

Automaticaly crop the figure in order to have the smallest space between the brain and the border of the picture.

bgcolor : array_like/string | None

The background color of the image.

transparent : bool | False

Specify if the exported figure have to contains a transparent background.

obj : VisbrainObj | None

Pass a Visbrain object if you want to use the camera of an other object for the sceen rendering.

kwargs : dict | {}

Optional arguments are passed to the VisbrainCanvas class.

set_stage(stage, idx_start, idx_end)[source][source]

Set stage.

stage : str, int

Stage to define. Should either be a string (e.g ‘art’, ‘rem’…) or an integer.

idx_start : int

Index where the stage begin.

idx_end : int

Index where the stage finish.


Get the transform value.


Get the unicolor value.


Get the visible_obj value.