Exemplo n.º 1
0
def set_jupyter_backend(backend: Optional[str] = None) -> bool:
    """
    Configure the jupyter plotting backend for pyvista.

    Parameters
    ----------
    backend : str, optional
        The pyvista plotting backend. For further details see
        :func:`pyvista.set_jupyter_backend`. If ``None``, defaults to
        :data:`JUPYTER_BACKEND`.

    Returns
    -------
    bool
        Whether the jupyter backend was successfully configured.

    Notes
    -----
    .. versionadded:: 0.1.0

    """
    result = False
    if active_kernel():
        try:
            if backend is None:
                backend = JUPYTER_BACKEND
            pv.set_jupyter_backend(backend)
            result = True
        except ImportError:
            logger.info("Unable to set the pyvista jupyter backend to '%s'", backend)
    else:
        logger.debug("No active IPython kernel available")

    return result
Exemplo n.º 2
0
def test_set_jupyter_backend_ipygany():
    pv.set_jupyter_backend('static')
    assert pv.rcParams['jupyter_backend'] == 'static'
    pv.set_jupyter_backend(None)
Exemplo n.º 3
0
def test_set_jupyter_backend_none(backend):
    pv.set_jupyter_backend(backend)
    assert pv.rcParams['jupyter_backend'] is None
Exemplo n.º 4
0
def test_set_jupyter_backend_ipygany_fail():
    with pytest.raises(ValueError, match='Invalid Jupyter notebook plotting backend'):
        pv.set_jupyter_backend('not a backend')
Exemplo n.º 5
0
def test_set_jupyter_backend_ipyvtklink():
    pv.set_jupyter_backend('ipyvtklink')
    assert pv.rcParams['jupyter_backend'] == 'ipyvtklink'
    pv.set_jupyter_backend(None)
Exemplo n.º 6
0
def test_set_jupyter_backend_panel():
    pv.set_jupyter_backend('panel')
    assert pv.global_theme.jupyter_backend == 'panel'
    pv.set_jupyter_backend(None)
Exemplo n.º 7
0
# -- pyvista configuration ---------------------------------------------------
import pyvista
import numpy as np

# Manage errors
pyvista.set_error_output_file("errors.txt")
# Ensure that offscreen rendering is used for docs generation
pyvista.OFF_SCREEN = True  # Not necessary - simply an insurance policy
# Preferred plotting style for documentation
pyvista.set_plot_theme("document")
pyvista.global_theme.window_size = [1024, 768]
pyvista.global_theme.font.size = 22
pyvista.global_theme.font.label_size = 22
pyvista.global_theme.font.title_size = 22
pyvista.global_theme.return_cpos = False
pyvista.set_jupyter_backend(None)
# Save figures in specified directory
pyvista.FIGURE_PATH = os.path.join(os.path.abspath("./images/"), "auto-generated/")
if not os.path.exists(pyvista.FIGURE_PATH):
    os.makedirs(pyvista.FIGURE_PATH)

# necessary when building the sphinx gallery
pyvista.BUILDING_GALLERY = True

# SG warnings
import warnings

warnings.filterwarnings(
    "ignore",
    category=UserWarning,
    message="Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.",
Exemplo n.º 8
0
def test_set_jupyter_backend_static():
    pv.set_jupyter_backend('static')
    assert pv.global_theme.jupyter_backend == 'static'
    pv.set_jupyter_backend(None)
Exemplo n.º 9
0
def test_set_jupyter_backend_none(backend):
    pv.set_jupyter_backend(backend)
    assert pv.global_theme.jupyter_backend is None
Exemplo n.º 10
0
def test_set_jupyter_backend_ipygany():
    pv.set_jupyter_backend('panel')
    assert pv.rcParams['jupyter_backend'] == 'panel'
    pv.set_jupyter_backend(None)
Exemplo n.º 11
0
def test_set_jupyter_backend_ipyvtk_simple():
    pv.set_jupyter_backend('ipyvtk_simple')
    assert pv.rcParams['jupyter_backend'] == 'ipyvtk_simple'
    pv.set_jupyter_backend('panel')