visbrain.gui.Figure¶
-
class
visbrain.gui.
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
- filesstr/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.
- pathstr | 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’, …]
- gridtuple | 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)…
- figtitlestr | None
Title of the entire figure.
- yfloat | 1.02
Distance between top and title of each axis (if title displayed).
- titlesstr/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.)
- xlabelsstr/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.)
- ylabelsstr/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.)
- figsizetuple | None
The size of the figure. Should be a tuple of integers.
- subspacedict | {}
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.
- rmaxbool | True
Remove borders of each axis.
- fig_bgcolorstr/tuple/list | None
Background color of the figure. By default, no background is used.
- ax_bgcolorstr/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_colorstr/tuple/list | ‘black’
Color of text elements (figure title, axes titles, x and y labels.)
- autocropbool | False
Specify if each picture has to be automatically cropped.
- autoresizebool | 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
(self, 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
- toaxisint
Integer to specify the axis to which add the colorbar.
- climtuple/list
A tuple of float/int describing the limit of the colorbar.
- cmapstr
The colormap to use (‘viridis’, ‘jet’, ‘Spectral’…)
- vminfloat | None
Minimum threshold. See the under parameter for further details.
- understring/tuple/list | ‘gray’
Every values bellow vmin will be set to the under color.
- vmaxfloat | None
Maximum threshold. See the over parameter for further details.
- overstring/tuple/list | ‘red’
Every values over vmax will be set to the over color.
- titlestring | None
Title of the colorbar.
- ycbfloat | 10.
Distance between the colorbar and it title (if defined).
- fz_titleint/float | 15
The fontsize of colorbar title.
- ticksstring/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_ticksint/float | 10
Fontsize of tick labels.
- outlinebool | False
Specify if the box arround the colorbar have to be displayed.
- orientationstring | ‘vertical’
Colorbar orientation. Use either ‘vertical’ or ‘horizontal’.
See also
shared_colorbar
colorbar shared by multiple subplots.
-
save
(self, saveas, dpi=300)[source][source]¶ Save the figure.
- Parameters
- saveasstring
Name of the saved figure.
- dpiint | 300
The resolution of the exported figure.
Add a colorbar to a particular axis.
- Parameters
- toaxisint
Integer to specify the axis to which add the colorbar.
- climtuple/list
A tuple of float/int describing the limit of the colorbar.
- cmapstr
The colormap to use (‘viridis’, ‘jet’, ‘Spectral’…)
- positionstr | ‘right’
Position of the shared colorbar. Use either ‘left’, ‘right’, or ‘bottom’.
- heightfloat | .5
Height of the colorbar.
- widthfloat | .02
Width of the colorbar.
- pltmarginfloat | .05
Margin between plots and the colorbar.
- figmarginfloat | .07
Margin between the edge of the figure and the colorbar.
- vminfloat | None
Minimum threshold. See the under parameter for further details.
- understring/tuple/list | ‘gray’
Every values bellow vmin will be set to the under color.
- vmaxfloat | None
Maximum threshold. See the over parameter for further details.
- overstring/tuple/list | ‘red’
Every values over vmax will be set to the over color.
- titlestring | None
Title of the colorbar.
- ycbfloat | 10.
Distance between the colorbar and it title (if defined).
- fz_titleint/float | 15
The fontsize of colorbar title.
- ticksstring/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_ticksint/float | 10
Fontsize of tick labels.
- outlinebool | False
Specify if the box arround the colorbar have to be displayed.
See also
colorbar_to_axis
add a specific colorbar to an axis.