How to use the pyvista.Plotter function in pyvista

To help you get started, we’ve selected a few pyvista examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyvista / pyvista / tests / test_plotting.py View on Github external
def test_volume_rendering():
    # Really just making sure no errors are thrown
    vol = examples.load_uniform()
    vol.plot(off_screen=OFF_SCREEN, volume=True, opacity='linear')

    plotter = pyvista.Plotter(off_screen=OFF_SCREEN)
    plotter.add_volume(vol, opacity='sigmoid', cmap='jet', n_colors=15)
    plotter.show()

    # Now test MultiBlock rendering
    data = pyvista.MultiBlock(dict(a=examples.load_uniform(),
                                   b=examples.load_uniform(),
                                   c=examples.load_uniform(),
                                   d=examples.load_uniform(),))
    data['a'].rename_array('Spatial Point Data', 'a')
    data['b'].rename_array('Spatial Point Data', 'b')
    data['c'].rename_array('Spatial Point Data', 'c')
    data['d'].rename_array('Spatial Point Data', 'd')
    data.plot(off_screen=OFF_SCREEN, volume=True, multi_colors=True, )
github pyvista / pyvista / tests / test_plotting.py View on Github external
def test_plot_label_fmt():
    plotter = pyvista.Plotter(off_screen=OFF_SCREEN)
    plotter.add_mesh(sphere)
    plotter.show_bounds(xlabel='My X', fmt=r'%.3f')
    plotter.show()
github pyvista / pyvista / tests / test_plotting.py View on Github external
def test_plot_invalid_add_scalar_bar():
    with pytest.raises(Exception):
        plotter = pyvista.Plotter()
        plotter.add_scalar_bar()
github holoviz / panel / panel / pane / vtk / dev / example_polydata.py View on Github external
# mesh points
vertices = np.array([[0, 0, 0],
                     [1, 0, 0],
                     [1, 1, 0],
                     [0, 1, 0],
                     [0.5, 0.5, -1]])

# mesh faces
faces = np.hstack([[4, 0, 1, 2, 3],  # square
                   [3, 0, 1, 4],     # triangle
                   [3, 1, 2, 4]])    # triangle

surf = pv.PolyData(vertices, faces)

# plot each face with a different color
plotter = pv.Plotter(notebook=True)
actor = plotter.add_mesh(surf, scalars=np.arange(3))
ctf = vtk.vtkColorTransferFunction()
ctf.AddRGBPoint(0,1,0,0)
ctf.AddRGBPoint(1,0,1,0)
ctf.AddRGBPoint(2,0,0,1)
actor.GetMapper().SetLookupTable(ctf)
plotter.ren_win.OffScreenRenderingOn()
plotter.ren_win.Render()
# plotter.show()


# lut = actor.GetMapper().GetLookupTable()

# from vtk.util import numpy_support
# with open('lutTable.txt', 'w') as f:
#     json.dump(numpy_support.vtk_to_numpy(lut.GetTable()).ravel().tolist(), f)
github pyvista / pyvista / examples / 01-filter / using-filters.py View on Github external
# Apply a threshold over a data range
threshed = dataset.threshold([100, 500])

outline = dataset.outline()

###############################################################################
# And now there is a thresholded version of the input dataset in the new
# ``threshed`` object. To learn more about what keyword arguments are available to
# alter how filters are executed, print the docstring for any filter attached to
# PyVista objects with either ``help(dataset.threshold)`` or using ``shift+tab``
# in an IPython environment.
#
# We can now plot this filtered dataset along side an outline of the original
# dataset

p = pv.Plotter()
p.add_mesh(outline, color="k")
p.add_mesh(threshed)
p.camera_position = [-2, 5, 3]
p.show()


###############################################################################
# What about other filters? Let's collect a few filter results and compare them:

contours = dataset.contour()
slices = dataset.slice_orthogonal()
glyphs = dataset.glyph(factor=1e-3, geom=pv.Sphere())

p = pv.Plotter(shape=(2, 2))
# Show the threshold
p.add_mesh(outline, color="k")
github pyvista / pyvista / examples / 02-plot / screenshot.py View on Github external
# sphinx_gallery_thumbnail_number = 2
import pyvista as pv
from pyvista import examples
import numpy as np
import matplotlib.pyplot as plt

# Get a sample file
filename = examples.planefile
mesh = pv.read(filename)


###############################################################################
# You can also take a screenshot without creating an interactive plot window
# using the :class:`pyvista.Plotter`:

plotter = pv.Plotter(off_screen=True)
plotter.add_mesh(mesh, color="orange")
plotter.show(auto_close=False)
# plotter.screenshot('airplane.png')
plotter.close()

###############################################################################
# The ``img`` array can be used to plot the screenshot in ``matplotlib``:

plt.imshow(plotter.image)
plt.show()
github pyvista / pyvista / examples / 02-plot / plot-gif.py View on Github external
"""

import pyvista as pv
import numpy as np

x = np.arange(-10, 10, 0.25)
y = np.arange(-10, 10, 0.25)
x, y = np.meshgrid(x, y)
r = np.sqrt(x**2 + y**2)
z = np.sin(r)

# Create and structured surface
grid = pv.StructuredGrid(x, y, z)

# Creat a plotter object and set the scalars to the Z height
plotter = pv.Plotter()
plotter.add_mesh(grid, scalars=z.ravel())

# setup camera and close
plotter.show(auto_close=False)

# Open a gif
plotter.open_gif('wave.gif')

pts = grid.points.copy()

# Update Z and write a frame for each updated position
nframe = 15
for phase in np.linspace(0, 2*np.pi, nframe + 1)[:nframe]:
    z = np.sin(r + phase)
    pts[:, -1] = z.ravel()
    plotter.update_coordinates(pts)
github holoviz / panel / panel / pane / vtk / dev / example_texture.py View on Github external
# mesh points
vertices = np.array([[0, 0, 0],
                     [1, 0, 0],
                     [1, 1, 0],
                     [0, 1, 0],
                     [0.5, 0.5, -1]])

# mesh faces
faces = np.hstack([[4, 0, 1, 2, 3],  # square
                   [3, 0, 1, 4],     # triangle
                   [3, 1, 2, 4]])    # triangle

surf = pv.PolyData(vertices, faces)

# plot each face with a different color
plotter = pv.Plotter(notebook=True)
actor = plotter.add_mesh(surf, scalars=np.arange(3))
#plotter.show()

import panel.pane.vtk.dev.vtk_render_serializer as rws

import panel as pn
pn.extension('vtk')
pan = pn.panel(plotter.ren_win)
plotter.ren_win.OffScreenRenderingOn()
plotter.ren_win.Render()

context = rws.VTKSerializer()
state = context.serialize(None, actor)

res = context.todict(state)
with open('actor.json', 'w') as f:
github pyvista / pyvista / examples / 02-plot / plot-over-line.py View on Github external
###############################################################################
# Volumetric Mesh
# +++++++++++++++
#
# First a 3D mesh example to demonstrate
mesh = examples.download_kitchen()

# Make two points to construct the line between
a = [mesh.bounds[0], mesh.bounds[2], mesh.bounds[4]]
b = [mesh.bounds[1], mesh.bounds[3], mesh.bounds[5]]

# Preview how this line intersects this mesh
line = pv.Line(a, b)

p = pv.Plotter()
p.add_mesh(mesh, style="wireframe", color="w")
p.add_mesh(line, color="b")
p.show()

###############################################################################
# Run the filter and produce a line plot
mesh.plot_over_line(a, b, resolution=100)


###############################################################################
# Flat Surface
# ++++++++++++
#
# We could also plot the values of a mesh that lies on a flat surface
mesh = examples.download_st_helens()
github akaszynski / pyansys / pyansys / cyclic_reader.py View on Github external
Returns
        -------
        cpos : list
            Camera position.

        """
        if grid is None:
            grid = self.mas_grid

        window_size = kwargs.pop('window_size', None)
        full_screen = kwargs.pop('full_screen', False)
        cmap = kwargs.pop('cmap', 'jet')

        # Plot off screen when not interactive
        plotter = pv.Plotter(off_screen=off_screen)
        if 'show_axes' in kwargs:
            plotter.add_axes()

        # set background
        plotter.background_color = kwargs.pop('background', None)

        rng = [np.nanmin(scalars), np.nanmax(scalars)]

        cs_cord = self._resultheader['csCord']
        if cs_cord > 1:
            matrix = self.cs_4x4(cs_cord, as_vtk_matrix=True)
            i_matrix = self.cs_4x4(cs_cord, as_vtk_matrix=True)
            i_matrix.Invert()
        else:
            matrix = vtk.vtkMatrix4x4()
            i_matrix = vtk.vtkMatrix4x4()