~~~~~~~~~~~~~~~~~~~~~~~~ """ import numpy as np import pyvista as pv from pyvista import examples pv.set_plot_theme('document') # download mesh mesh = examples.download_cow() decimated = mesh.decimate_boundary(target_reduction=0.75) p = pv.Plotter(notebook=0, shape=(1, 2), border=False) p.subplot(0, 0) p.add_text('Original mesh', font_size=24) p.add_mesh(mesh, show_edges=True, color=True) p.subplot(0, 1) p.add_text('Decimated version', font_size=24) p.add_mesh(decimated, color=True, show_edges=True) p.link_views() # link all the views # Set a camera position to all linked views p.camera_position = [ (15, 5, 0), (0, 0, 0), (0, 1, 0) ]
def test_remove_actor(uniform): plotter = pyvista.Plotter() plotter.add_mesh(uniform.copy(), name='data') plotter.add_mesh(uniform.copy(), name='data') plotter.add_mesh(uniform.copy(), name='data') plotter.show(before_close_callback=verify_cache_image)
def test_user_annotations_scalar_bar_volume(uniform): p = pyvista.Plotter() p.add_volume(uniform, annotations={100.: 'yum'}) p.show(before_close_callback=verify_cache_image)
def test_clear(): plotter = pyvista.Plotter(off_screen=OFF_SCREEN) plotter.add_mesh(sphere) plotter.clear() plotter.show()
def test_multi_renderers(): plotter = pyvista.Plotter(shape=(2, 2), off_screen=OFF_SCREEN) plotter.subplot(0, 0) plotter.add_text('Render Window 0', font_size=30) sphere = pyvista.Sphere() plotter.add_mesh(sphere, scalars=sphere.points[:, 2]) plotter.add_scalar_bar('Z', vertical=True) plotter.subplot(0, 1) plotter.add_text('Render Window 1', font_size=30) plotter.add_mesh(pyvista.Cube(), show_edges=True) plotter.subplot(1, 0) plotter.add_text('Render Window 2', font_size=30) plotter.add_mesh(pyvista.Arrow(), color='y', show_edges=True) plotter.subplot(1, 1) plotter.add_text('Render Window 3', position=(0., 0.), font_size=30, viewport=True) plotter.add_mesh(pyvista.Cone(), color='g', show_edges=True, culling=True) plotter.add_bounding_box(render_lines_as_tubes=True, line_width=5) plotter.show_bounds(all_edges=True) plotter.update_bounds_axes() plotter.show() # Test subplot indices (2 rows by 1 column) plotter = pyvista.Plotter(shape=(2, 1), off_screen=OFF_SCREEN) # First row plotter.subplot(0, 0) plotter.add_mesh(pyvista.Sphere()) # Second row plotter.subplot(1, 0) plotter.add_mesh(pyvista.Cube()) plotter.show() # Test subplot indices (1 row by 2 columns) plotter = pyvista.Plotter(shape=(1, 2), off_screen=OFF_SCREEN) # First column plotter.subplot(0, 0) plotter.add_mesh(pyvista.Sphere()) # Second column plotter.subplot(0, 1) plotter.add_mesh(pyvista.Cube()) plotter.show() with pytest.raises(IndexError): # Test bad indices plotter = pyvista.Plotter(shape=(1, 2), off_screen=OFF_SCREEN) plotter.subplot(0, 0) plotter.add_mesh(pyvista.Sphere()) plotter.subplot(1, 0) plotter.add_mesh(pyvista.Cube()) plotter.show() # Test subplot 3 on left, 1 on right plotter = pyvista.Plotter(shape='3|1', off_screen=OFF_SCREEN) # First column plotter.subplot(0) plotter.add_mesh(pyvista.Sphere()) plotter.subplot(1) plotter.add_mesh(pyvista.Cube()) plotter.subplot(2) plotter.add_mesh(pyvista.Cylinder()) plotter.subplot(3) plotter.add_mesh(pyvista.Cone()) plotter.show() # Test subplot 3 on bottom, 1 on top plotter = pyvista.Plotter(shape='1|3', off_screen=OFF_SCREEN) # First column plotter.subplot(0) plotter.add_mesh(pyvista.Sphere()) plotter.subplot(1) plotter.add_mesh(pyvista.Cube()) plotter.subplot(2) plotter.add_mesh(pyvista.Cylinder()) plotter.subplot(3) plotter.add_mesh(pyvista.Cone()) plotter.show()
def test_update(): plotter = pyvista.Plotter(off_screen=True) plotter.update() plotter.close()
def test_box_axes(): plotter = pyvista.Plotter(off_screen=True) plotter.add_axes(box=True, box_args={'color_box': True}) plotter.add_mesh(pyvista.Sphere()) plotter.show()
def test_plot_show_grid(): plotter = pyvista.Plotter() plotter.show_grid() plotter.add_mesh(sphere) plotter.close()
def test_set_camera_position(cpos, sphere): plotter = pyvista.Plotter(off_screen=OFF_SCREEN) plotter.add_mesh(sphere) plotter.camera_position = cpos plotter.show()
def test_add_background_image(as_global): plotter = pyvista.Plotter() plotter.add_mesh(sphere) plotter.add_background_image(examples.mapfile, as_global=as_global) plotter.show()
def test_plot_bounds_axes_with_no_data(): plotter = pyvista.Plotter() plotter.show_bounds() plotter.close()
import pyvista as pv from pyvista import examples # Load St Helens DEM and warp the topography image = examples.download_st_helens() mesh = image.warp_by_scalar() ############################################################################### # Global Value # ++++++++++++ # # You can also apply a global opacity value to the mesh by passing a single # float between 0 and 1 which would enable you to see objects behind the mesh: p = pv.Plotter() p.add_mesh(image.contour(), line_width=5,) p.add_mesh(mesh, opacity=0.85, color=True) p.show() ############################################################################### # Note that you can specify ``use_transparency=True`` to convert opacities to # transparencies in any of the following examples. ############################################################################### # Transfer Functions # ++++++++++++++++++ # # It's possible to apply an opacity mapping to any scalar array plotted. You # can specify either a single static value to make the mesh transparent on all
# initialize method method = ApproxGalerkin(domain, idomain, quadrature, cov, cov_data) # formation and assembly A, B = method.direct() Aref, Bref = method.exact_kron() # solution neigs = 10 lambda_h, f_h = eigsh(A, neigs, B) # ordered smallest to highest method.normalize_ev(f_h) # eval geometry ep = [np.linspace(0, 1, 100)] * domain.dim x, y, z = [domain.eval(ep, k) for k in range(domain.dim)] # plot at evaluation points plotter = pv.Plotter() cmap = plt.get_cmap('jet', 2048) mesh = pv.StructuredGrid(x, y, z) data = method.eval_ef(ep, f_h, -1) plotter.add_mesh(mesh, show_edges=False, scalars=data.transpose(), stitle=' ', cmap=cmap) plotter.show_axes() plotter.view_xy() plotter.show()
surf.plot(cpos="xy", show_edges=True) ############################################################################### # Note that some of the outer edges are unconstrained and the triangulation # added unwanted triangles. We can mitigate that with the ``alpha`` parameter. surf = cloud.delaunay_2d(alpha=1.0) surf.plot(cpos="xy", show_edges=True) ############################################################################### # We could also add a polygon to ignore during the triangulation via the # ``edge_source`` parameter. # Define a polygonal hole with a clockwise polygon ids = [22, 23, 24, 25, 35, 45, 44, 43, 42, 32] # Create a polydata to store the boundary polygon = pv.PolyData() # Make sure it has the same points as the mesh being triangulated polygon.points = points # But only has faces in regions to ignore polygon.faces = np.array([len(ids),] + ids) surf = cloud.delaunay_2d(alpha=1.0, edge_source=polygon) p = pv.Plotter() p.add_mesh(surf, show_edges=True) p.add_mesh(polygon, color="red", opacity=0.5) p.show(cpos="xy")
def test_key_press_event(): plotter = pyvista.Plotter(off_screen=False) plotter.key_press_event(None, None) plotter.close()
def test_set_camera_position_invalid(cpos, sphere): plotter = pyvista.Plotter(off_screen=OFF_SCREEN) plotter.add_mesh(sphere) with pytest.raises(pyvista.core.errors.InvalidCameraError): plotter.camera_position = cpos
def test_show_axes(): # if not closed correctly, a seg fault occurs when exitting plotter = pyvista.Plotter(off_screen=False) plotter.show_axes() plotter.close()
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()
def test_invalid_n_arrays(): with pytest.raises(ValueError): plotter = pyvista.Plotter(off_screen=OFF_SCREEN) plotter.add_mesh(sphere, scalars=np.arange(10)) plotter.show()
def test_plot_invalid_add_scalar_bar(): with pytest.raises(AttributeError): plotter = pyvista.Plotter() plotter.add_scalar_bar()
def test_scalars_by_name(): plotter = pyvista.Plotter(off_screen=OFF_SCREEN) data = examples.load_uniform() plotter.add_mesh(data, scalars='Spatial Cell Data') plotter.show()
def test_add_lines_invalid(): plotter = pyvista.Plotter() with pytest.raises(TypeError): plotter.add_lines(range(10))
def test_plot_texture_associated(): """"Test adding a texture to a plot""" globe = examples.load_globe() plotter = pyvista.Plotter(off_screen=OFF_SCREEN) plotter.add_mesh(globe, texture=True) plotter.show()
def test_open_gif_invalid(): plotter = pyvista.Plotter(off_screen=OFF_SCREEN) with pytest.raises(ValueError): plotter.open_gif('file.abs')
def plot_example(): p = pv.Plotter() p.add_mesh(mesh) p.add_bounding_box() return p.show()
def test_add_axes_twice(): plotter = pyvista.Plotter(off_screen=OFF_SCREEN) plotter.add_axes() plotter.add_axes(interactive=True)
def test_plot_eye_dome_lighting_enable_disable(airplane): p = pyvista.Plotter() p.add_mesh(airplane) p.enable_eye_dome_lighting() p.disable_eye_dome_lighting() p.show(before_close_callback=verify_cache_image)
def test_add_point_labels_always_visible(always_visible): # just make sure it runs without exception plotter = pyvista.Plotter(off_screen=OFF_SCREEN) plotter.add_point_labels(np.array([[0, 0, 0]]), ['hello world'], always_visible=always_visible) plotter.show()
def test_add_background_image_global(): plotter = pyvista.Plotter() plotter.add_mesh(sphere) plotter.add_background_image(examples.mapfile, as_global=True) plotter.show(before_close_callback=verify_cache_image)
""" import pyvista as pv from pyvista import examples # Load the statue mesh mesh = examples.download_nefertiti() mesh.rotate_x(-90.) # rotate to orient with the skybox # Download skybox cubemap = examples.download_sky_box_cube_map() ############################################################################### # Let's render the mesh with a base color of "linen" to give it a metal looking # finish. p = pv.Plotter() p.add_actor(cubemap.to_skybox()) p.set_environment_texture( cubemap) # For reflecting the environment off the mesh p.add_mesh(mesh, color='linen', pbr=True, metallic=0.8, roughness=0.1, diffuse=1) # Define a nice camera perspective cpos = [(-313.40, 66.09, 1000.61), (0.0, 0.0, 0.0), (0.018, 0.99, -0.06)] p.show(cpos=cpos)