def plot(var_item, off_screen=None, full_screen=None, screenshot=None, interactive=True, cpos=None, window_size=None, show_bounds=False, show_axes=None, notebook=None, background=None, text='', return_img=False, eye_dome_lighting=False, volume=False, parallel_projection=False, use_ipyvtk=None, jupyter_backend=None, return_viewer=False, return_cpos=False, jupyter_kwargs={}, theme=None, hidden_line_removal=None, anti_aliasing=None, zoom=None, **kwargs): """Plot a vtk or numpy object. Parameters ---------- var_item : pyvista.DataSet, vtk, or numpy object VTK object or ``numpy`` array to be plotted. off_screen : bool, optional Plots off screen when ``True``. Helpful for saving screenshots without a window popping up. Defaults to the global setting ``pyvista.OFF_SCREEN``. full_screen : bool, optional Opens window in full screen. When enabled, ignores ``window_size``. Defaults to active theme setting in :attr:`pyvista.global_theme.full_screen <pyvista.themes.DefaultTheme.full_screen>`. screenshot : str or bool, optional Saves screenshot to file when enabled. See: :func:`Plotter.screenshot() <pyvista.Plotter.screenshot>`. Default ``False``. When ``True``, takes screenshot and returns ``numpy`` array of image. interactive : bool, optional Allows user to pan and move figure. Defaults to :attr:`pyvista.global_theme.interactive <pyvista.themes.DefaultTheme.interactive>`. cpos : list, optional List of camera position, focal point, and view up. window_size : list, optional Window size in pixels. Defaults to global theme :attr:`pyvista.global_theme.window_size <pyvista.themes.DefaultTheme.window_size>`. show_bounds : bool, optional Shows mesh bounds when ``True``. Default ``False``. show_axes : bool, optional Shows a vtk axes widget. If ``None``, enabled according to :attr:`pyvista.global_theme.axes.show <pyvista.themes._AxesConfig.show>`. notebook : bool, optional When ``True``, the resulting plot is placed inline a jupyter notebook. Assumes a jupyter console is active. background : str or sequence, optional Color of the background. text : str, optional Adds text at the bottom of the plot. return_img : bool, optional Returns numpy array of the last image rendered. eye_dome_lighting : bool, optional Enables eye dome lighting. volume : bool, optional Use the :func:`Plotter.add_volume() <pyvista.Plotter.add_volume>` method for volume rendering. parallel_projection : bool, optional Enable parallel projection. use_ipyvtk : bool, optional Deprecated. Instead, set the backend either globally with ``pyvista.set_jupyter_backend('ipyvtklink')`` or with ``backend='ipyvtklink'``. jupyter_backend : str, optional Jupyter notebook plotting backend to use. One of the following: * ``'none'`` : Do not display in the notebook. * ``'static'`` : Display a static figure. * ``'ipygany'`` : Show a ``ipygany`` widget * ``'panel'`` : Show a ``panel`` widget. This can also be set globally with :func:`pyvista.set_jupyter_backend`. return_viewer : bool, optional Return the jupyterlab viewer, scene, or display object when plotting with jupyter notebook. return_cpos : bool, optional Return the last camera position from the render window when enabled. Defaults to value in theme settings. jupyter_kwargs : dict, optional Keyword arguments for the Jupyter notebook plotting backend. theme : pyvista.themes.DefaultTheme, optional Plot-specific theme. hidden_line_removal : bool, optional Wireframe geometry will be drawn using hidden line removal if the rendering engine supports it. See :func:`Plotter.enable_hidden_line_removal <Plotter.enable_hidden_line_removal>`. Defaults to the theme setting :attr:`pyvista.global_theme.hidden_line_removal <pyvista.themes.DefaultTheme.hidden_line_removal>`. anti_aliasing : bool, optional Enable or disable anti-aliasing. Defaults to the theme setting :attr:`pyvista.global_theme.antialiasing <pyvista.themes.DefaultTheme.antialiasing>`. zoom : float, optional Camera zoom. A value greater than 1 is a zoom-in, a value less than 1 is a zoom-out. Must be greater than 0. **kwargs : optional keyword arguments See :func:`pyvista.Plotter.add_mesh` for additional options. Returns ------- cpos : list List of camera position, focal point, and view up. Returned only when ``return_cpos=True`` or set in the default global or plot theme. Not returned when in a jupyter notebook and ``return_viewer=True``. image : np.ndarray Numpy array of the last image when either ``return_img=True`` or ``screenshot=True`` is set. Not returned when in a jupyter notebook with ``return_viewer=True``. Optionally contains alpha values. Sized: * [Window height x Window width x 3] if the theme sets ``transparent_background=False``. * [Window height x Window width x 4] if the theme sets ``transparent_background=True``. widget IPython widget when ``return_viewer=True``. Examples -------- Plot a simple sphere while showing its edges. >>> import pyvista >>> mesh = pyvista.Sphere() >>> mesh.plot(show_edges=True) """ if notebook is None: notebook = scooby.in_ipykernel() if theme is None: theme = pyvista.global_theme if anti_aliasing is not None: theme.antialiasing = anti_aliasing # undocumented kwarg used within pytest to run a function before closing before_close_callback = kwargs.pop('before_close_callback', None) eye_dome_lighting = kwargs.pop("edl", eye_dome_lighting) show_grid = kwargs.pop('show_grid', False) auto_close = kwargs.get('auto_close', theme.auto_close) if notebook: off_screen = notebook plotter = Plotter(off_screen=off_screen, notebook=notebook, theme=theme) if show_axes is None: show_axes = theme.axes.show if show_axes: plotter.add_axes() plotter.set_background(background) if isinstance(var_item, list): if len(var_item) == 2: # might be arrows isarr_0 = isinstance(var_item[0], np.ndarray) isarr_1 = isinstance(var_item[1], np.ndarray) if isarr_0 and isarr_1: plotter.add_arrows(var_item[0], var_item[1]) else: for item in var_item: if volume or (isinstance(item, np.ndarray) and item.ndim == 3): plotter.add_volume(item, **kwargs) else: plotter.add_mesh(item, **kwargs) else: for item in var_item: if volume or (isinstance(item, np.ndarray) and item.ndim == 3): plotter.add_volume(item, **kwargs) else: plotter.add_mesh(item, **kwargs) else: if volume or (isinstance(var_item, np.ndarray) and var_item.ndim == 3): plotter.add_volume(var_item, **kwargs) else: plotter.add_mesh(var_item, **kwargs) if text: plotter.add_text(text) if show_grid: plotter.show_grid() elif show_bounds: plotter.show_bounds() if cpos is None: cpos = plotter.get_default_cam_pos() plotter.camera_position = cpos plotter.camera_set = False else: plotter.camera_position = cpos if zoom is not None: plotter.camera.zoom(zoom) if eye_dome_lighting: plotter.enable_eye_dome_lighting() if parallel_projection: plotter.enable_parallel_projection() return plotter.show(window_size=window_size, auto_close=auto_close, interactive=interactive, full_screen=full_screen, screenshot=screenshot, return_img=return_img, use_ipyvtk=use_ipyvtk, jupyter_backend=jupyter_backend, before_close_callback=before_close_callback, jupyter_kwargs=jupyter_kwargs, return_viewer=return_viewer, return_cpos=return_cpos)
def plot(var_item, off_screen=None, full_screen=False, screenshot=None, interactive=True, cpos=None, window_size=None, show_bounds=False, show_axes=True, notebook=None, background=None, text='', return_img=False, eye_dome_lighting=False, volume=False, parallel_projection=False, use_ipyvtk=None, **kwargs): """Plot a vtk or numpy object. Parameters ---------- item : vtk or numpy object VTK object or numpy array to be plotted. off_screen : bool Plots off screen when True. Helpful for saving screenshots without a window popping up. full_screen : bool, optional Opens window in full screen. When enabled, ignores window_size. Default False. screenshot : str or bool, optional Saves screenshot to file when enabled. See: help(pyvistanterface.Plotter.screenshot). Default disabled. When True, takes screenshot and returns numpy array of image. window_size : list, optional Window size in pixels. Defaults to [1024, 768] show_bounds : bool, optional Shows mesh bounds when True. Default False. Alias ``show_grid`` also accepted. notebook : bool, optional When True, the resulting plot is placed inline a jupyter notebook. Assumes a jupyter console is active. show_axes : bool, optional Shows a vtk axes widget. Enabled by default. text : str, optional Adds text at the bottom of the plot. volume : bool, optional Use the ``add_volume`` method for volume rendering. use_ipyvtk : bool, optional Use the ``ipyvtk-simple`` ``ViewInteractiveWidget`` to visualize the plot within a juyterlab notebook. **kwargs : optional keyword arguments See help(Plotter.add_mesh) for additional options. Returns ------- cpos : list List of camera position, focal point, and view up. img : numpy.ndarray Array containing pixel RGB and alpha. Sized: [Window height x Window width x 3] for transparent_background=False [Window height x Window width x 4] for transparent_background=True Returned only when screenshot enabled """ if notebook is None: notebook = scooby.in_ipykernel() # undocumented kwarg used within pytest to run a function before closing before_close_callback = kwargs.pop('before_close_callback', None) eye_dome_lighting = kwargs.pop("edl", eye_dome_lighting) show_grid = kwargs.pop('show_grid', False) auto_close = kwargs.get('auto_close', rcParams['auto_close']) if notebook: off_screen = notebook plotter = Plotter(off_screen=off_screen, notebook=notebook) if show_axes: plotter.add_axes() plotter.set_background(background) if isinstance(var_item, list): if len(var_item) == 2: # might be arrows isarr_0 = isinstance(var_item[0], np.ndarray) isarr_1 = isinstance(var_item[1], np.ndarray) if isarr_0 and isarr_1: plotter.add_arrows(var_item[0], var_item[1]) else: for item in var_item: if volume or (isinstance(item, np.ndarray) and item.ndim == 3): plotter.add_volume(item, **kwargs) else: plotter.add_mesh(item, **kwargs) else: for item in var_item: if volume or (isinstance(item, np.ndarray) and item.ndim == 3): plotter.add_volume(item, **kwargs) else: plotter.add_mesh(item, **kwargs) else: if volume or (isinstance(var_item, np.ndarray) and var_item.ndim == 3): plotter.add_volume(var_item, **kwargs) else: plotter.add_mesh(var_item, **kwargs) if text: plotter.add_text(text) if show_grid: plotter.show_grid() elif show_bounds: plotter.show_bounds() if cpos is None: cpos = plotter.get_default_cam_pos() plotter.camera_position = cpos plotter.camera_set = False else: plotter.camera_position = cpos if eye_dome_lighting: plotter.enable_eye_dome_lighting() if parallel_projection: plotter.enable_parallel_projection() result = plotter.show(window_size=window_size, auto_close=auto_close, interactive=interactive, full_screen=full_screen, screenshot=screenshot, return_img=return_img, use_ipyvtk=use_ipyvtk, before_close_callback=before_close_callback) # Result will be handled by plotter.show(): cpos or [cpos, img] return result
if not os.path.exists(EXAMPLES_PATH): os.makedirs(EXAMPLES_PATH) # Send VTK messages to the logging module: send_errors_to_logging() # Set up panel for interactive notebook rendering try: if os.environ['PYVISTA_USE_PANEL'].lower() == 'false': rcParams['use_panel'] = False elif os.environ['PYVISTA_USE_PANEL'].lower() == 'true': rcParams['use_panel'] = True except KeyError: pass # Only initialize panel if in a Jupyter environment if scooby.in_ipykernel(): try: import panel panel.extension('vtk') except (ImportError, RuntimeError): rcParams['use_panel'] = False # Set preferred plot theme try: theme = os.environ['PYVISTA_PLOT_THEME'].lower() set_plot_theme(theme) except KeyError: pass # Set a parameter to control default print format for floats FLOAT_FORMAT = "{:.3e}"
def test_ipy(): scooby.in_ipykernel()
def plot(var_item, off_screen=None, full_screen=False, screenshot=None, interactive=True, cpos=None, window_size=None, show_bounds=False, show_axes=None, notebook=None, background=None, text='', return_img=False, eye_dome_lighting=False, volume=False, parallel_projection=False, use_ipyvtk=None, jupyter_backend=None, return_viewer=False, jupyter_kwargs={}, theme=None, **kwargs): """Plot a vtk or numpy object. Parameters ---------- item : vtk or numpy object VTK object or ``numpy`` array to be plotted. off_screen : bool Plots off screen when ``True``. Helpful for saving screenshots without a window popping up. full_screen : bool, optional Opens window in full screen. When enabled, ignores ``window_size``. Default ``False``. screenshot : str or bool, optional Saves screenshot to file when enabled. See: ``help(pyvista.Plotter.screenshot)``. Default ``False``. When ``True``, takes screenshot and returns ``numpy`` array of image. window_size : list, optional Window size in pixels. Defaults to ``[1024, 768]`` show_bounds : bool, optional Shows mesh bounds when ``True``. Default ``False``. Alias ``show_grid`` also accepted. notebook : bool, optional When ``True``, the resulting plot is placed inline a jupyter notebook. Assumes a jupyter console is active. show_axes : bool, optional Shows a vtk axes widget. If ``None``, enabled according to ``pyvista.global_theme.axes.show``. text : str, optional Adds text at the bottom of the plot. volume : bool, optional Use the ``add_volume`` method for volume rendering. use_ipyvtk : bool, optional Deprecated. Instead, set the backend either globally with ``pyvista.set_jupyter_backend('ipyvtklink')`` or with ``backend='ipyvtklink'``. jupyter_backend : str, optional Jupyter notebook plotting backend to use. One of the following: * ``'none'`` : Do not display in the notebook. * ``'static'`` : Display a static figure. * ``'ipygany'`` : Show a ``ipygany`` widget * ``'panel'`` : Show a ``panel`` widget. This can also be set globally with ``pyvista.set_jupyter_backend`` jupyter_kwargs : dict, optional Keyword arguments for the Jupyter notebook plotting backend. theme : pyvista.themes.DefaultTheme, optional Plot specific theme. **kwargs : optional keyword arguments See help(Plotter.add_mesh) for additional options. Returns ------- cpos : list List of camera position, focal point, and view up. img : numpy.ndarray Array containing pixel RGB and alpha. Sized: [Window height x Window width x 3] for transparent_background=False [Window height x Window width x 4] for transparent_background=True Returned only when screenshot enabled Examples -------- Plot a simple sphere while showing its edges. >>> import pyvista >>> mesh = pyvista.Sphere() >>> mesh.plot(show_edges=True) # doctest:+SKIP """ if notebook is None: notebook = scooby.in_ipykernel() if theme is None: theme = pyvista.global_theme # undocumented kwarg used within pytest to run a function before closing before_close_callback = kwargs.pop('before_close_callback', None) eye_dome_lighting = kwargs.pop("edl", eye_dome_lighting) show_grid = kwargs.pop('show_grid', False) auto_close = kwargs.get('auto_close', theme.auto_close) if notebook: off_screen = notebook plotter = Plotter(off_screen=off_screen, notebook=notebook, theme=theme) if show_axes is None: show_axes = theme.axes.show if show_axes: plotter.add_axes() plotter.set_background(background) if isinstance(var_item, list): if len(var_item) == 2: # might be arrows isarr_0 = isinstance(var_item[0], np.ndarray) isarr_1 = isinstance(var_item[1], np.ndarray) if isarr_0 and isarr_1: plotter.add_arrows(var_item[0], var_item[1]) else: for item in var_item: if volume or (isinstance(item, np.ndarray) and item.ndim == 3): plotter.add_volume(item, **kwargs) else: plotter.add_mesh(item, **kwargs) else: for item in var_item: if volume or (isinstance(item, np.ndarray) and item.ndim == 3): plotter.add_volume(item, **kwargs) else: plotter.add_mesh(item, **kwargs) else: if volume or (isinstance(var_item, np.ndarray) and var_item.ndim == 3): plotter.add_volume(var_item, **kwargs) else: plotter.add_mesh(var_item, **kwargs) if text: plotter.add_text(text) if show_grid: plotter.show_grid() elif show_bounds: plotter.show_bounds() if cpos is None: cpos = plotter.get_default_cam_pos() plotter.camera_position = cpos plotter.camera_set = False else: plotter.camera_position = cpos if eye_dome_lighting: plotter.enable_eye_dome_lighting() if parallel_projection: plotter.enable_parallel_projection() result = plotter.show(window_size=window_size, auto_close=auto_close, interactive=interactive, full_screen=full_screen, screenshot=screenshot, return_img=return_img, use_ipyvtk=use_ipyvtk, jupyter_backend=jupyter_backend, before_close_callback=before_close_callback, jupyter_kwargs=jupyter_kwargs, return_viewer=return_viewer) # Result will be handled by plotter.show(): cpos or [cpos, img] or # the jupyterlab scene when return_viewer is True return result
def test_ipy(): result = scooby.in_ipykernel()