1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
.. _plotting:
Plotting
--------
When plotting with the interactive rendering windows in VTK, several keyboard
shortcuts are available:
+-------------------------------------+-----------------+-------------------------------------------------------+
| Key | Action |
+=====================================+=================+=======================================================+
| Linux/Windows | Mac | |
+-------------------------------------+-----------------+-------------------------------------------------------+
| ``q`` | Close the rendering window |
+-------------------------------------+-----------------+-------------------------------------------------------+
| ``f`` | Focus and zoom in on a point |
+-------------------------------------+-----------------+-------------------------------------------------------+
| ``v`` | Isometric camera view |
+-------------------------------------+-----------------+-------------------------------------------------------+
| ``w`` | Switch all datasets to a ``wireframe`` representation |
+-------------------------------------+-----------------+-------------------------------------------------------+
| ``r`` | Reset the camera to view all datasets |
+-------------------------------------+-----------------+-------------------------------------------------------+
| ``s`` | Switch all datasets to a ``surface`` representation |
+-------------------------------------+-----------------+-------------------------------------------------------+
| ``shift+click`` or ``middle-click`` | ``shift+click`` | Pan the rendering scene |
+-------------------------------------+-----------------+-------------------------------------------------------+
| ``left-click`` | ``cmd+click`` | Rotate the rendering scene in 3D |
+-------------------------------------+-----------------+-------------------------------------------------------+
| ``ctrl+click`` | | Rotate the rendering scene in 2D (view-plane) |
+-------------------------------------+-----------------+-------------------------------------------------------+
| ``mouse-wheel`` or ``right-click`` | ``ctl+click`` | Continuously zoom the rendering scene |
+-------------------------------------+-----------------+-------------------------------------------------------+
| ``shift+s`` | Save a screenshot (only on ``BackgroundPlotter``) |
+-------------------------------------+-----------------+-------------------------------------------------------+
| ``shift+c`` | Enable interactive cell selection/picking |
+-------------------------------------+-----------------+-------------------------------------------------------+
| ``up``/``down`` | Zoom in and out |
+-------------------------------------+-----------------+-------------------------------------------------------+
| ``+``/``-`` | Increase/decrease the point size and line widths |
+-------------------------------------+-----------------+-------------------------------------------------------+
Plotting in a Jupyter Notebook
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Static and interactive inline plots are possible using a Jupyter
notebook. The code snippet below will create a static screenshot of
the rendering and display it in the Jupyter notebook:
.. jupyter-execute::
import pyvista as pv
sphere = pv.Sphere()
sphere.plot(jupyter_backend='static')
It is possible to use the ``Plotter`` class as well.
.. jupyter-execute::
plotter = pv.Plotter(notebook=True)
plotter.add_mesh(sphere)
plotter.show(jupyter_backend='static')
Additionally, you can generate interactive plots by leveraging our
jupyter plotting backend ``trame``. You can even use it to create
interactive documentation online.
.. jupyter-execute::
plotter = pv.Plotter(window_size=(600, 400))
plotter.background_color = 'w'
plotter.enable_anti_aliasing()
plotter.add_mesh(sphere, color='lightblue', show_edges=True)
plotter.show(jupyter_backend='static')
For more details, see the section on :ref:`jupyter_plotting`.
Background Plotting
~~~~~~~~~~~~~~~~~~~
PyVista provides a plotter that enables users to create a rendering
window in the background that remains interactive while the user
performs their processing. This creates the ability to make a
rendering scene and interactively add or remove datasets from the
scene as well as has some useful menu functions for common scene
manipulation or export tasks. To get started, try instantiating the
:class:`pyvistaqt.BackgroundPlotter`:
.. code-block:: python
import pyvista as pv
import pyvistaqt as pvqt
from pyvista import examples
dataset = examples.load_hexbeam()
p = pvqt.BackgroundPlotter()
p.add_mesh(dataset)
p.show_bounds(grid=True, location='back')
Plot Time Series Data
~~~~~~~~~~~~~~~~~~~~~
This example outlines how to plot data where the spatial reference and data
values change through time:
.. code-block:: python
from threading import Thread
import time
import numpy as np
import pyvista as pv
import pyvistaqt as pvqt
from pyvista import examples
globe = examples.load_globe()
texture = examples.load_globe_texture()
globe.point_data['scalars'] = np.random.rand(globe.n_points)
globe.set_active_scalars('scalars')
plotter = pvqt.BackgroundPlotter()
plotter.add_mesh(
globe,
lighting=False,
show_edges=True,
texture=texture,
scalars='scalars',
)
plotter.view_isometric()
# shrink globe in the background
def shrink():
for i in range(50):
globe.points *= 0.95
# Update scalars
globe.point_data['scalars'] = np.random.rand(globe.n_points)
time.sleep(0.5)
thread = Thread(target=shrink)
thread.start()
.. figure:: ../../images/gifs/shrink-globe.gif
|