class visbrain.objects.TimeFrequencyObj(name, data=None, sf=1.0, method='fourier', nperseg=256, f_min=1.0, f_max=160.0, f_step=1.0, baseline=None, norm=None, n_window=None, overlap=0.0, window=None, c_parameter=20, cmap='viridis', clim=None, vmin=None, under='gray', vmax=None, over='red', interpolation='nearest', max_pts=-1, parent=None, transform=None, verbose=None, **kw)[source][source]

Compute the time-frequency map (or spectrogram).

The time-frequency decomposition can be assessed using :

  • The fourier transform
  • Morlet’s wavelet
  • Multi-taper
name : string | None

Name of the time-frequency object.

data : array_like

Array of data of shape (N,)

sf : float | 1.

The sampling frequency.

method : {‘fourier’, ‘wavelet’, ‘multitaper’}

The method to use to compute the time-frequency decomposition.

nperseg : int | 256

Length of each segment. Argument pass to the scipy.signal.spectrogram function (for ‘fourier’ and ‘multitaper’ method).

overlap : float | 0.

Overlap between segments. Must be between 0. and 1.

f_min : float | 1.

Minimum frequency (for ‘wavelet’ method).

f_max : float | 160.

Maximum frequency (for ‘wavelet’ method).

f_step : float | 2.

Frequency step between two consecutive frequencies (for ‘wavelet’ method).

baseline : array_like | None

Baseline period (for ‘wavelet’ method).

norm : int | None

The normalization type (for ‘wavelet’ method).. See the normalization function.

n_window : int | None

If this parameter is an integer, the time-frequency map is going to be averaged into smaller windows (for ‘wavelet’ method).

window : {‘flat’, ‘hanning’, ‘hamming’, ‘bartlett’, ‘blackman’}

Windowing method for averaging. By default, ‘flat’ is used for Wavelet and ‘hamming’ for Fourier.

c_parameter : int | 20

Parameter ‘c’ described in doi:10.1155/2011/980805 (for ‘multitaper’ method)

clim : tuple | None

Colorbar limits. If None, clim=(data.min(), data.max())

cmap : string | None

Colormap name.

vmin : float | None

Minimum threshold of the colorbar.

under : string/tuple/array_like | None

Color for values under vmin.

vmax : float | None

Maximum threshold of the colorbar.

over : string/tuple/array_like | None

Color for values over vmax.

interpolation : string | ‘nearest’

Interpolation method for the image. See vispy.scene.visuals.Image for availables interpolation methods.

max_pts : int | -1

Maximum number of points of the image along the x or y axis. This parameter is essentially used to solve OpenGL issues with very large images.

transform : VisPy.visuals.transforms | None

VisPy transformation to set to the parent node.

parent : VisPy.parent | None

Markers 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 TimeFrequencyObj
>>> n, sf = 512, 256  # number of time-points and sampling frequency
>>> time = np.arange(n) / sf  # time vector
>>> data = np.sin(2 * np.pi * 25. * time) + np.random.rand(n)
>>> tf = TimeFrequencyObj('tf', data, sf)
>>> tf.preview(axis=True)


__init__(name[, data, sf, method, nperseg, …]) Init.
describe_tree() Tree description.
preview([bgcolor, axis, xyz, show, obj, size]) Previsualize the result.
screenshot(saveas[, print_size, dpi, unit, …]) Take a screeshot of the scene.
set_data(data[, sf, method, nperseg, f_min, …]) Compute TF and set data to the ImageObj.
set_shortcuts_to_canvas(canvas) Set shortcuts to a VisbrainCanvas.
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.

Get the clim value.


Get the cmap value.


Get the interpolation value.


Get the name value.


Get the over value.


Get the parent value.

preview(bgcolor='black', axis=False, xyz=False, show=True, obj=None, size=(1200, 800), **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.

kwargs : dict | {}

Optional arguments are passed to the VisbrainCanvas class.

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_data(data, sf=1.0, method='fourier', nperseg=256, f_min=1.0, f_max=160.0, f_step=1.0, baseline=None, norm=None, n_window=None, overlap=0.0, window=None, c_parameter=20, clim=None, cmap='viridis', vmin=None, under=None, vmax=None, over=None)[source][source]

Compute TF and set data to the ImageObj.


Get the transform value.


Get the under value.


Get the visible_obj value.


Get the vmax value.


Get the vmin value.

Examples using visbrain.objects.TimeFrequencyObj