Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Use a greedy_terrain_decimation to created a decimated mesh
terrain = mlab.pipeline.greedy_terrain_decimation(data)
terrain.filter.error_measure = 'number_of_triangles'
terrain.filter.number_of_triangles = 5000
terrain.filter.compute_normals = True
# Plot it black the lines of the mesh
lines = mlab.pipeline.surface(terrain, color=(0, 0, 0),
representation='wireframe')
# The terrain decimator has done the warping. We control the warping
# scale via the actor's scale.
lines.actor.actor.scale = [1, 1, 0.2]
# Display the surface itself.
surf = mlab.pipeline.surface(terrain, colormap='gist_earth',
vmin=1450, vmax=1650)
surf.actor.actor.scale = [1, 1, 0.2]
# Display the original regular grid. This time we have to use a
# warp_scalar filter.
warp = mlab.pipeline.warp_scalar(data, warp_scale=0.2)
grid = mlab.pipeline.surface(warp, color=(1, 1, 1),
representation='wireframe')
mlab.view(-17, 46, 143, [1.46, 8.46, 269.4])
mlab.show()
the ``Mayavi`` package and Delaunay triangulation.
This method is useful to visualize the output of an optimisation routine on
a 2-dimensional parameter space.
*Note: this method requires Mayavi to be installed.*
"""
# Import mayavi
from mayavi import mlab
# Create a figure
mlab.figure(1, fgcolor=(0, 0, 0), bgcolor=(1, 1, 1))
# Visualize the points
p = mlab.points3d(x, y, f, f, scale_mode='none', scale_factor=0)
# Create and visualize the mesh
mesh = mlab.pipeline.delaunay2d(p)
surf = mlab.pipeline.surface(mesh)
# Display the created surface
mlab.show()
def map_grid(f, bounds, n, parallel=False, args=None):
###############################################################################
# Display city names
for city, index in cities.items():
label = mlab.text(x[index], y[index], city, z=z[index],
width=0.016 * len(city), name=city)
label.property.shadow = True
###############################################################################
# Display continents outline, using the VTK Builtin surface 'Earth'
from mayavi.sources.builtin_surface import BuiltinSurface
continents_src = BuiltinSurface(source='earth', name='Continents')
# The on_ratio of the Earth source controls the level of detail of the
# continents outline.
continents_src.data_source.on_ratio = 2
continents = mlab.pipeline.surface(continents_src, color=(0, 0, 0))
###############################################################################
# Display a semi-transparent sphere, for the surface of the Earth
# We use a sphere Glyph, throught the points3d mlab function, rather than
# building the mesh ourselves, because it gives a better transparent
# rendering.
sphere = mlab.points3d(0, 0, 0, scale_mode='none',
scale_factor=2,
color=(0.67, 0.77, 0.93),
resolution=50,
opacity=0.7,
name='Earth')
# These parameters, as well as the color, where tweaked through the GUI,
# with the record mode to produce lines of code usable in a script.
interpolation_degree=0)
elif mesh.element_type == "hex":
tmesh = PostProcess.TessellateHexes(mesh,np.zeros_like(mesh.points),
interpolation_degree=0)
figure = mlab.figure(bgcolor=(1,1,1),fgcolor=(1,1,1),size=(1000,800))
mlab.quiver3d(Xs, Ys, Zs, self.anisotropic_orientations[:,0],
self.anisotropic_orientations[:,1], self.anisotropic_orientations[:,2],
color=(0.,128./255,128./255),line_width=2)
src = mlab.pipeline.scalar_scatter(tmesh.x_edges.T.copy().flatten(),
tmesh.y_edges.T.copy().flatten(), tmesh.z_edges.T.copy().flatten())
src.mlab_source.dataset.lines = tmesh.connections
lines = mlab.pipeline.stripper(src)
h_edges = mlab.pipeline.surface(lines, color = (0,0,0), line_width=2)
mlab.show()
field = mlab.pipeline.scalar_field(x, y, z, Phi)
ipw = mlab.pipeline.image_plane_widget(field)
mlab.outline(field)
surface = mlab.pipeline.builtin_surface()
surface.source = 'sphere'
surface.data_source.radius = .4
surface.data_source.phi_resolution = 200
surface.data_source.theta_resolution = 200
probe_filter = tvtk.ProbeFilter()
configure_input(probe_filter, surface.data_source)
configure_source_data(probe_filter, field.outputs[0])
probe = mlab.pipeline.user_defined(surface, filter=probe_filter)
surf = mlab.pipeline.surface(probe)
fig = mlab.gcf()
################################################################################
# Finally, to inspect the VTK Pipeline (and not the Mayavi one, we
# use the TVTK pipeline browser)
# Note that for Mayavi version < 3.4.1, there is a bug in the
# PipelineBrowser preventing a good display of this pipeline.
from tvtk.pipeline.browser import PipelineBrowser
browser = PipelineBrowser(fig.scene)
browser.show()
mlab.show()
def view(src):
""" Open up a mayavi scene and display the dataset in it.
"""
from mayavi import mlab
mayavi = mlab.get_engine()
fig = mlab.figure(bgcolor=(1, 1, 1), fgcolor=(0, 0, 0),)
mayavi.add_source(src)
mlab.pipeline.surface(src, opacity=0.1)
mlab.pipeline.surface(mlab.pipeline.extract_edges(src),
color=(0, 0, 0), )
# Extract the data
import tarfile
lucy_tar_file = tarfile.open('lucy.tar.gz')
try:
os.mkdir('lucy_data')
except:
pass
lucy_tar_file.extractall('lucy_data')
lucy_tar_file.close()
# Path to the lucy ply file
lucy_ply_file = join('lucy_data', 'lucy.ply')
# Render the lucy ply file
mlab.pipeline.surface(mlab.pipeline.open(lucy_ply_file))
mlab.show()
import shutil
shutil.rmtree('lucy_data')
pos_thresh = threshold_filter(mesh, low=old.pos_lims[0])
pos = mlab.pipeline.surface(
pos_thresh, colormap="YlOrRd", figure=self._f,
vmin=old.pos_lims[1], vmax=old.pos_lims[2])
pos_bar = mlab.scalarbar(pos, nb_labels=5)
pos_bar.reverse_lut = True
pos_bar.scalar_bar_representation.position = (0.53, 0.01)
pos_bar.scalar_bar_representation.position2 = (0.42, 0.09)
self._format_cbar_text(pos_bar)
else:
pos = pos_bar = None
if old.neg_lims is not None:
with warnings.catch_warnings(record=True):
neg_thresh = threshold_filter(mesh, up=old.neg_lims[0])
neg = mlab.pipeline.surface(
neg_thresh, colormap="PuBu", figure=self._f,
vmin=old.neg_lims[1], vmax=old.neg_lims[2])
neg_bar = mlab.scalarbar(neg, nb_labels=5)
neg_bar.scalar_bar_representation.position = (0.05, 0.01)
neg_bar.scalar_bar_representation.position2 = (0.42, 0.09)
self._format_cbar_text(neg_bar)
else:
neg = neg_bar = None
return OverlayDisplay(self, array_id, pos, pos_bar, neg, neg_bar)
scalars = np.array(list(G.nodes())) + 5
pts = mlab.points3d(
xyz[:, 0],
xyz[:, 1],
xyz[:, 2],
scalars,
scale_factor=0.1,
scale_mode="none",
colormap="Blues",
resolution=20,
)
pts.mlab_source.dataset.lines = np.array(list(G.edges()))
tube = mlab.pipeline.tube(pts, tube_radius=0.01)
mlab.pipeline.surface(tube, color=(0.8, 0.8, 0.8))
mlab.show()