visbrain.objects.SceneObj¶
-
class
visbrain.objects.
SceneObj
(bgcolor='black', camera_state={}, verbose=None, **kwargs)[source][source]¶ Create a scene and add objects to it.
- Parameters
- bgcolorstring | ‘black’
Background color of the scene.
- showbool | True
Display the canvas.
- camera_statedict | {}
The default camera state to use.
- verbosestring
Verbosity level.
Notes
List of supported shortcuts :
s : save the figure
delete : reset all views
Methods
__init__
(self[, bgcolor, camera_state, verbose])Init.
add_to_subplot
(self, obj[, row, col, …])Add object to subplot.
link
(self, \*args)Link the camera of several objects of the scene.
preview
(self[, mpl])Previsualize the result.
record_animation
(self, name[, n_pic])Record an animated scene and save as a *.gif file.
render
(self)Render the canvas.
screenshot
(self, saveas[, print_size, dpi, …])Take a screeshot of the scene.
-
add_to_subplot
(self, obj, row=0, col=0, row_span=1, col_span=1, title=None, title_size=12.0, title_color='white', title_bold=True, use_this_cam=False, rotate=None, zoom=None, camera_state={}, width_max=None, height_max=None)[source][source]¶ Add object to subplot.
- Parameters
- objvisbrain.object
The visbrain object to add.
- rowint | 0
Row location for the object.
- colint | 0
Columns location for the object.
- row_spanint | 1
Number of rows to use.
- col_spanint | 1
Number of columns to use.
- titlestring | None
Subplot title.
- title_sizefloat | 12.
Title font size.
- title_colorstring/tuple/array_like | ‘white’
Color of the title.
- title_boldbool | True
Use bold title.
- use_this_cambool | False
If you add multiple objects to the same scene and if you want to use the camera of an object as the reference, turn this parameter to True.
- rotatestring | None
Rotate the scene (only available for 3D objects). Use :
‘top’ : top view
‘bottom’ : bottom view
‘left’ : left view
‘right’ : right view
‘front’ : front view
‘back’ : bottom view
‘side-fl’ : side view (front-left)
‘side-fr’ : side view (front-right)
‘side-bl’ : side view (back-left)
‘side-br’ : side view (back-right)
- zoomfloat | None
Zoom level. If zoom is in ]0, 1[, the size of the object decrease. If zoom=1, no zoom is applied. If zoom > 1., the size of the object increase. For example, zoom=2 means that the displayed object will appear twice as large.
- camera_statedict | {}
Arguments to pass to the camera.
- width_maxfloat | None
Maximum width of the subplot.
- height_maxfloat | None
Maximum height of the subplot.
-
link
(self, *args)[source][source]¶ Link the camera of several objects of the scene.
- Parameters
- argslist
List of tuple describing subplot locations. Alternatively, use -1 to link all cameras.
Examples
>>> # Link cameras of subplots (0, 0), (0, 1) and (1, 0) >>> sc.link((0, 0), (0, 1), (1, 0))
-
preview
(self, mpl=False)[source][source]¶ Previsualize the result.
- Parameters
- mplbool | False
Use Matplotlib to display the scene. This result in a non interactive figure.
-
record_animation
(self, name, n_pic=10)[source][source]¶ Record an animated scene and save as a *.gif file.
Note that this method :
Only 3D objects can be animated.
Requires the python package imageio
- Parameters
- namestring
Name of the gif file (e.g ‘myfile.gif’)
- n_picint | 10
Number of pictures to use to render the gif.
-
render
(self)[source][source]¶ Render the canvas.
- Returns
- imgarray_like
Array of shape (n_rows, n_columns, 4) where 4 describes the RGBA components.
-
screenshot
(self, saveas, print_size=None, dpi=300.0, unit='centimeter', factor=None, region=None, autocrop=False, bgcolor=None, transparent=False, line_width=1.0)[source][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.
- Parameters
- saveasstr
The name of the file to be saved. This file must contains a extension like .png, .tiff, .jpg…
- print_sizetuple | 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.
- dpifloat | 300.
Dots per inch for printing the image.
- unit{‘centimeter’, ‘millimeter’, ‘pixel’, ‘inch’}
Unit of the printed size.
- factorfloat | None
If you don’t want to use the print_size input, factor simply multiply the resolution of your screen.
- regiontuple | None
Select a specific region. Must be a tuple of four integers each one describing (x_start, y_start, width, height).
- autocropbool | False
Automaticaly crop the figure in order to have the smallest space between the brain and the border of the picture.
- bgcolorarray_like/string | None
The background color of the image.
- transparentbool | False
Specify if the exported figure have to contains a transparent background.