| 1 |
""" |
| 2 |
.. _point_sprites_example: |
| 3 |
|
| 4 |
Point Sprite Shapes |
| 5 |
~~~~~~~~~~~~~~~~~~~ |
| 6 |
|
| 7 |
By default, VTK renders points as squares. PyVista provides several |
| 8 |
built-in point sprite shapes that replace the default square with a |
| 9 |
custom shape via a GLSL fragment shader. |
| 10 |
|
| 11 |
The ``point_shape`` parameter can be passed directly to |
| 12 |
:func:`pyvista.Plotter.add_mesh` or set globally via |
| 13 |
:attr:`pyvista.global_theme.point_shape <pyvista.plotting.themes.Theme.point_shape>`. |
| 14 |
""" |
| 15 |
|
| 16 |
# sphinx_gallery_start_ignore |
| 17 |
# shader customizations do not work in interactive examples |
| 18 |
PYVISTA_GALLERY_FORCE_STATIC_IN_DOCUMENT = True |
| 19 |
# sphinx_gallery_end_ignore |
| 20 |
|
| 21 |
|
| 22 |
import numpy as np |
| 23 |
import pyvista as pv |
| 24 |
|
| 25 |
# %% |
| 26 |
# Available Shapes |
| 27 |
# ~~~~~~~~~~~~~~~~ |
| 28 |
# Six built-in shapes are available: ``'circle'``, ``'triangle'``, |
| 29 |
# ``'hexagon'``, ``'diamond'``, ``'asterisk'``, and ``'star'``. |
| 30 |
|
| 31 |
rng = np.random.default_rng(42) |
| 32 |
points = rng.random((1000, 3)) |
| 33 |
cloud = pv.PolyData(points) |
| 34 |
cloud['elevation'] = cloud.points[:, 2] |
| 35 |
|
| 36 |
shapes = ['circle', 'triangle', 'hexagon', 'diamond', 'asterisk', 'star'] |
| 37 |
pl = pv.Plotter(shape=(2, 3)) |
| 38 |
|
| 39 |
for i, shape in enumerate(shapes): |
| 40 |
pl.subplot(i // 3, i % 3) |
| 41 |
pl.add_mesh( |
| 42 |
cloud, |
| 43 |
scalars='elevation', |
| 44 |
style='points', |
| 45 |
point_shape=shape, |
| 46 |
point_size=25, |
| 47 |
show_scalar_bar=False, |
| 48 |
) |
| 49 |
pl.add_text(shape, font_size=12) |
| 50 |
|
| 51 |
pl.link_views() |
| 52 |
pl.show() |
| 53 |
|
| 54 |
|
| 55 |
# %% |
| 56 |
# Using ``point_shape`` with ``add_mesh`` |
| 57 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 58 |
# The ``point_shape`` parameter works alongside ``point_size`` and |
| 59 |
# ``style='points'``. If ``render_points_as_spheres`` is ``True`` |
| 60 |
# (either explicitly or via the global theme), it is automatically |
| 61 |
# disabled when a ``point_shape`` is set. |
| 62 |
|
| 63 |
pl = pv.Plotter(shape=(1, 3)) |
| 64 |
|
| 65 |
pl.subplot(0, 0) |
| 66 |
pl.add_mesh( |
| 67 |
cloud, scalars='elevation', style='points', point_size=15, show_scalar_bar=False |
| 68 |
) |
| 69 |
pl.add_text('Default (squares)', font_size=10) |
| 70 |
|
| 71 |
pl.subplot(0, 1) |
| 72 |
pl.add_mesh( |
| 73 |
cloud, |
| 74 |
scalars='elevation', |
| 75 |
style='points', |
| 76 |
point_shape='circle', |
| 77 |
point_size=15, |
| 78 |
show_scalar_bar=False, |
| 79 |
) |
| 80 |
pl.add_text('Circles', font_size=10) |
| 81 |
|
| 82 |
pl.subplot(0, 2) |
| 83 |
pl.add_mesh( |
| 84 |
cloud, |
| 85 |
scalars='elevation', |
| 86 |
style='points', |
| 87 |
point_shape='star', |
| 88 |
point_size=15, |
| 89 |
show_scalar_bar=False, |
| 90 |
) |
| 91 |
pl.add_text('Stars', font_size=10) |
| 92 |
|
| 93 |
pl.link_views() |
| 94 |
pl.show() |