.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorial/09_trame/c_trame_scalars.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorial_09_trame_c_trame_scalars.py: Control Scalar Array ~~~~~~~~~~~~~~~~~~~~ Extending our simple example to have a dropdown menu to control which scalar array is used to color the mesh. .. GENERATED FROM PYTHON SOURCE LINES 8-73 .. code-block:: Python import pyvista as pv from pyvista import examples from pyvista.trame.ui import plotter_ui from trame.app import get_server from trame.ui.vuetify3 import SinglePageLayout from trame.widgets import vuetify3 pv.OFF_SCREEN = True server = get_server() state, ctrl = server.state, server.controller mesh = examples.download_antarctica_velocity() pl = pv.Plotter() actor = pl.add_mesh(mesh) pl.view_xy() @state.change("scalars") def set_scalars(scalars=mesh.active_scalars_name, **kwargs): actor.mapper.array_name = scalars actor.mapper.scalar_range = mesh.get_data_range(scalars) ctrl.view_update() @state.change("log_scale") def set_log_scale(log_scale=False, **kwargs): actor.mapper.lookup_table.log_scale = log_scale ctrl.view_update() with SinglePageLayout(server) as layout: with layout.toolbar: vuetify3.VSpacer() vuetify3.VCheckbox( label="Log Scale", v_model=("log_scale", False), hide_details=True, density="compact", outlined=True, ) vuetify3.VSelect( label="Scalars", v_model=("scalars", mesh.active_scalars_name), items=("array_list", list(mesh.point_data.keys())), hide_details=True, density="compact", outlined=True, classes="pt-1 ml-2", style="max-width: 250px", ) with layout.content: with vuetify3.VContainer( fluid=True, classes="pa-0 fill-height", ): # Use PyVista UI template for Plotters view = plotter_ui(pl) ctrl.view_update = view.update server.start() .. GENERATED FROM PYTHON SOURCE LINES 74-81 .. raw:: html
Open In Colab
.. _sphx_glr_download_tutorial_09_trame_c_trame_scalars.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/pyvista/pyvista-tutorial/gh-pages?urlpath=lab/tree/notebooks/tutorial/09_trame/c_trame_scalars.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: c_trame_scalars.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: c_trame_scalars.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_