.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/Widgets/plot_widget3d_plane.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. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_Widgets_plot_widget3d_plane.py: 3D Plane Widget =============== A draggable axis-aligned plane in a 3-D panel, rendered as a translucent quad spanning the panel's bounds. Drag it in the browser to slide it along its normal — ideal as a slice selector through a volume or point cloud. Add it with ``plot.add_widget("plane", axis=..., position=...)``. .. GENERATED FROM PYTHON SOURCE LINES 10-13 .. code-block:: Python import numpy as np import anyplotlib as apl .. GENERATED FROM PYTHON SOURCE LINES 14-17 A point cloud to slice ---------------------- A Gaussian blob of points; the plane widget will pick out a z-slab. .. GENERATED FROM PYTHON SOURCE LINES 17-32 .. code-block:: Python rng = np.random.default_rng(0) n = 4000 pts = rng.normal(0, 8, size=(n, 3)) + 24 # centred in a 0..48 box xs, ys, zs = pts[:, 0], pts[:, 1], pts[:, 2] fig, ax = apl.subplots(1, 1, figsize=(520, 500)) cloud = ax.scatter3d(xs, ys, zs, color="#4fc3f7", point_size=3, x_label="x", y_label="y", z_label="z") plane = cloud.add_widget("plane", axis="z", position=24, color="#40c4ff", alpha=0.15) fig .. raw:: html
.. GENERATED FROM PYTHON SOURCE LINES 33-38 Read the slice position on drag ------------------------------- ``pointer_move`` fires as the plane slides; ``plane.position`` is the current location along its normal. You can also move it from Python with ``plane.set(position=...)``. .. GENERATED FROM PYTHON SOURCE LINES 38-48 .. code-block:: Python @plane.add_event_handler("pointer_move") def _on_drag(event): print("z-slice at", round(plane.position, 1)) fig.set_help("Drag the blue plane along z to move the slice.") fig # Interactive .. raw:: html
.. raw:: html .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.500 seconds) .. _sphx_glr_download_auto_examples_Widgets_plot_widget3d_plane.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_widget3d_plane.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_widget3d_plane.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_widget3d_plane.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_