visbrain.Figure

class visbrain.Figure(files, path=None, grid=None, figtitle=None, y=1.02, titles=None, xlabels=None, ylabels=None, figsize=None, subspace={'bottom': 0.1, 'hspace': 0.3, 'left': 0.05, 'right': 1.0, 'top': 0.9, 'wspace': 0.0}, rmax=True, fig_bgcolor=None, ax_bgcolor=None, text_color='black', autocrop=False, autoresize=False)[source][source]

Automatically arange pictures in a grid and save a paper ready figure.

This class can be used to generate figures to be then used in a paper. For example, if you export 10 pictures, you may want to concatenate them in a (5, 2) grid and add a colorbar.

Parameters:
files : str/list/tuple

Files to load. If it’s a string, only one file will be loaded. Otherwise, if files is a iterable object of strings (list, tuple) all the files will be loaded.

path : str | None

Specify where files are located. If all files are in separate folders, use the files variable : files = [‘path1/file1.png’, ‘path2/file2.jpg’, …]. If all pictures are in the same folder, use path=’path2myfolder/’ and files=[‘file1.png’, ‘file2.jpg’, …]

grid : tuple | None

Tuple of integers describing how to arange figures. The grid describe (n_rows, n_columns) of the final figure. If grid is None all pictures will be displayed on a line. For example, if 12 pictures are loaded, grid could be (6, 2), (4, 3)…

figtitle : str | None

Title of the entire figure.

y : float | 1.02

Distance between top and title of each axis (if title displayed).

titles : str/list/tuple | None

Specify the title of each figure. If titles is None, no title will be added. If titles is a string, the same title will be applied to all figures. If titles is a list/tuple of strings, the strings inside will be used to set the title of each picture independantly (must have the same length as files.)

xlabels : str/list/tuple | None

Specify the x-axis label of each figure. If xlabels is None, no label will be added. If xlabels is a string, the same label will be applied to all figures. If xlabels is a list/tuple of strings, the strings inside will be used to set the label of each picture independantly (must have the same length as files.)

ylabels : str/list/tuple | None

Specify the y-axis label of each figure. If ylabels is None, no label will be added. If ylabels is a string, the same label will be applied to all figures. If ylabels is a list/tuple of strings, the strings inside will be used to set the label of each picture independantly (must have the same length as files.)

figsize : tuple | None

The size of the figure. Should be a tuple of integers.

subspace : dict | {}

Control margins and the distance between subplots. By default : {‘left’: 0., ‘right’: 1., ‘bottom’: 0., ‘top’: .9, ‘wspace’: 0., ‘hspace’: 0.05}. Use:

  • ‘left’ (default 0.): left side of subplots
  • ‘right’ (default 1.): right side of subplots
  • ‘bottom’ (default 0.): bottom side of subplots
  • ‘top’ (default .9): top of subplots
  • ‘hspace’ (default .05): amount of height reserved for white space between subplots, expressed as a fraction of the average axis height.
  • ‘wspace’ (default 0.): amount of width reserved for blank space between subplots, expressed as a fraction of the average axis width.
rmax : bool | True

Remove borders of each axis.

fig_bgcolor : str/tuple/list | None

Background color of the figure. By default, no background is used.

ax_bgcolor : str/tuple/list | None

Background color of each axis. If None, no background will be used. If ax_bgcolor is a string, the same background will be used for all axes. Finally, use a list of colors to control the background color of each axis. This is a very important parameter for transparent pictures (like png or tiff files).

text_color : str/tuple/list | ‘black’

Color of text elements (figure title, axes titles, x and y labels.)

autocrop : bool | False

Specify if each picture has to be automatically cropped.

autoresize : bool | False

Specify if all pictures have to be resized. If True, all pictures will be resized according to the minimum size along row axis. For further controls, define autoresize as a dictionary. Use the key ‘axis’ to specify if pictures have to share the same height (0) or width (1). Use ‘extend’ if the smallest (False) or the largest have to be considered as the reference.

colorbar_to_axis(toaxis, clim, cmap, vmin=None, under='gray', vmax=None, over='red', title=None, ycb=10.0, fz_title=15, ticks='complete', fz_ticks=10, outline=False, orientation='vertical')[source][source]

Add a colorbar to a particular axis.

Parameters:
toaxis : int

Integer to specify the axis to which add the colorbar.

clim : tuple/list

A tuple of float/int describing the limit of the colorbar.

cmap : str

The colormap to use (‘viridis’, ‘jet’, ‘Spectral’…)

vmin : float | None

Minimum threshold. See the under parameter for further details.

under : string/tuple/list | ‘gray’

Every values bellow vmin will be set to the under color.

vmax : float | None

Maximum threshold. See the over parameter for further details.

over : string/tuple/list | ‘red’

Every values over vmax will be set to the over color.

title : string | None

Title of the colorbar.

ycb : float | 10.

Distance between the colorbar and it title (if defined).

fz_title : int/float | 15

The fontsize of colorbar title.

ticks : string/int/float/np.ndarray | ‘complete’

Ticks of the colorbar. This parameter is only active if clim is defined. Use ‘complete’ to see only the minimum, maximum, vmin and vmax (if defined). Use ‘minmax’ to only see the maximum and minimum. If ticks is a float, an linear interpolation between the maximum and minimum will be used. Finally, if ticks is a NumPy array, it will be used as colorbar ticks directly.

fz_ticks : int/float | 10

Fontsize of tick labels.

outline : bool | False

Specify if the box arround the colorbar have to be displayed.

orientation : string | ‘vertical’

Colorbar orientation. Use either ‘vertical’ or ‘horizontal’.

See also

shared_colorbar
colorbar shared by multiple subplots.
save(saveas, dpi=300)[source][source]

Save the figure.

Parameters:
saveas : string

Name of the saved figure.

dpi : int | 300

The resolution of the exported figure.

shared_colorbar(clim, cmap, position='right', height=0.5, width=0.02, pltmargin=0.02, figmargin=0.07, vmin=None, under='gray', vmax=None, over='red', title=None, ycb=10.0, fz_title=15, ticks='complete', fz_ticks=10, outline=False)[source][source]

Add a colorbar to a particular axis.

Parameters:
toaxis : int

Integer to specify the axis to which add the colorbar.

clim : tuple/list

A tuple of float/int describing the limit of the colorbar.

cmap : str

The colormap to use (‘viridis’, ‘jet’, ‘Spectral’…)

position : str | ‘right’

Position of the shared colorbar. Use either ‘left’, ‘right’, or ‘bottom’.

height : float | .5

Height of the colorbar.

width : float | .02

Width of the colorbar.

pltmargin : float | .05

Margin between plots and the colorbar.

figmargin : float | .07

Margin between the edge of the figure and the colorbar.

vmin : float | None

Minimum threshold. See the under parameter for further details.

under : string/tuple/list | ‘gray’

Every values bellow vmin will be set to the under color.

vmax : float | None

Maximum threshold. See the over parameter for further details.

over : string/tuple/list | ‘red’

Every values over vmax will be set to the over color.

title : string | None

Title of the colorbar.

ycb : float | 10.

Distance between the colorbar and it title (if defined).

fz_title : int/float | 15

The fontsize of colorbar title.

ticks : string/int/float/np.ndarray | ‘complete’

Ticks of the colorbar. This parameter is only active if clim is defined. Use ‘complete’ to see only the minimum, maximum, vmin and vmax (if defined). Use ‘minmax’ to only see the maximum and minimum. If ticks is a float, an linear interpolation between the maximum and minimum will be used. Finally, if ticks is a NumPy array, it will be used as colorbar ticks directly.

fz_ticks : int/float | 10

Fontsize of tick labels.

outline : bool | False

Specify if the box arround the colorbar have to be displayed.

See also

colorbar_to_axis
add a specific colorbar to an axis.
show()[source][source]

Display the figure.

Examples using visbrain.Figure