How to use the mayavi.mlab.figure function in mayavi

To help you get started, we’ve selected a few mayavi 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 phoebe-project / phoebe2 / phoebe-testlib / test_synthetic / test_compare2_0.py View on Github external
plt.colorbar(out[2])
    ax = plt.subplot(224)
    plt.title("Radial velocity")
    out = system.plot2D(ref=0, select='rv', ax=ax)
    plt.colorbar(out[2])
    
    tools.summarize(system)
    
    plt.show()
    
    from mayavi import mlab
    mlab.figure()
    system.plot3D()
    mlab.figure()
    system.plot3D(velos=True)
    mlab.figure()
    system.plot3D(normals=True)
    
    mlab.show()
github enthought / mayavi / integrationtests / mayavi / test_texture.py View on Github external
def test_texture_curve(self):
        """ Test texture on mlab.surf """
        mlab.figure()
        X, Y = numpy.mgrid[-1:1:20j,-1:1:20j]
        Z = -numpy.cos(Y*X)+.5
        source = mlab.surf(X, Y, Z, color=(1., 1., 1.))

        # ensure the figure is closed at the end of the test
        self.addCleanup(self.mlab_close_all)

        # Apply the texture
        self.add_texture(source, "plane")

        # Zoom in closer for analysis
        mlab.view(67.2, 47, 2.1, [0.22, 0.13, -0.6])

        mlab.savefig(self.filename, size=(400, 300))

        # Check the saved image (if texture fails, std ~ 10)
github zinka / arraytool / arraytool / src / arraytool / planar.py View on Github external
# converting 'F' from linear to dB scale, if needed
        if(scale == "linear"):
            F_plt = abs(F)
            ss = "in linear scale"
        elif(scale == "dB"):
            F = 20 * np.log10(abs(F))
            # cutoff the "F" below some limit ... just for the plotting purpose
            F_plt = cutoff(F, dB_limit)
            ss = "in dB scale"

        # plotting F_plt
        if(plot_type):
            if(plot_type == "rect"):  # rectangular plot
                if (mayavi_app):  # opens the 3D plot in MayaVi Application
                    mlab.options.backend = 'envisage'
                mlab.figure(fgcolor=fgcolor, bgcolor=bgcolor)
                plt3d = mlab.surf(u, v, F_plt, warp_scale='auto')
                ranges1 = [u_min, u_max, v_min, v_max, F_plt.min(), F_plt.max()]
                mlab.axes(xlabel='u', ylabel='v', zlabel=f1,
                          ranges=ranges1, nb_labels=5)
                mlab.title(n1 + ff + ss, size=0.35)
                mlab.colorbar(orientation="vertical", nb_labels=5)
                plt3d.scene.isometric_view()
                mlab.show()
            if(plot_type == "contour"):  # contour plot
                plt.contourf(u, v, F_plt)
                vs = plt.Circle((0, 0), radius=1, edgecolor='w', fill=False)
                ax = plt.gca(); ax.add_patch(vs)
                plt.axis('image'); plt.grid(True)
                plt.xlabel(r'$u,\ \mathrm{where}\ u=\sin \theta \cos \phi\ \mathrm{in}\ \mathrm{the}\ \mathrm{visible-space}$', fontsize=16)
                plt.ylabel(r'$v,\ \mathrm{where}\ v=\sin \theta \sin \phi\ \mathrm{in}\ \mathrm{the}\ \mathrm{visible-space}$', fontsize=16)
                plt.colorbar(format='$%.2f$')
github the-virtual-brain / tvb-library / tvb / simulator / plot / mayavi_tools.py View on Github external
def surface_pattern(surface, vertex_colours, custom_lut=None, foci=None):
        """
        Plot a surface and colour it based on a vector of length number of 
        vertices (vertex_colours).

        * How to obtain a pretty picture (from Mayavi's gui): 
        
          - set surf_mesh color to rgb(237, 217, 221)
          - add a surface module derived from surf_mesh; set 'Actor' 
            representation to wireframe; colour 'gray'.
          - enable contours of scalar_surf  
        """
        fig = mlab.figure(figure="surface pattern", fgcolor=(0.5, 0.5, 0.5))
        surf_mesh = mlab.triangular_mesh(surface.vertices[:, 0],
                                         surface.vertices[:, 1],
                                         surface.vertices[:, 2],
                                         surface.triangles,
                                         figure=fig)
        sm_obj = surf_mesh.mlab_source
        scalar_data = surf_mesh.mlab_source.dataset.point_data
        scalar_data.scalars = vertex_colours
        scalar_data.scalars.name = 'Scalar data'
        scalar_data.update()
        scalar_mesh = mlab.pipeline.set_active_attribute(surf_mesh, point_scalars='Scalar data')
        scalar_surf = mlab.pipeline.surface(scalar_mesh)

        if custom_lut is not None:
            # and finally we put this LUT back in the surface object. We could have
            # added any 255*4 array rather than modifying an existing LUT.
github fwilliams / deep-geometric-prior / reconstruct_single_patch.py View on Github external
def plot_correspondences(model, uv, x, pi):
    y = model(uv).detach().squeeze().cpu().numpy()

    from mayavi import mlab
    mlab.figure(bgcolor=(1, 1, 1))
    mlab.points3d(x[:, 0], x[:, 1], x[:, 2], color=(1, 0, 0), scale_factor=0.01)
    mlab.points3d(y[:, 0], y[:, 1], y[:, 2], color=(0, 1, 0), scale_factor=0.01)
    x = x[pi].detach().squeeze().cpu().numpy()

    for i in range(x.shape[0]):
        lx = [x[i, 0], y[i, 0]]
        ly = [x[i, 1], y[i, 1]]
        lz = [x[i, 2], y[i, 2]]

        mlab.plot3d(lx, ly, lz, color=(0.1, 0.1, 0.1), tube_radius=None)
    mlab.show()
github charlesq34 / frustum-pointnets / kitti / kitti_object.py View on Github external
def show_lidar_with_boxes(pc_velo, objects, calib,
                          img_fov=False, img_width=None, img_height=None): 
    ''' Show all LiDAR points.
        Draw 3d box in LiDAR point cloud (in velo coord system) '''
    if 'mlab' not in sys.modules: import mayavi.mlab as mlab
    from viz_util import draw_lidar_simple, draw_lidar, draw_gt_boxes3d

    print(('All point num: ', pc_velo.shape[0]))
    fig = mlab.figure(figure=None, bgcolor=(0,0,0),
        fgcolor=None, engine=None, size=(1000, 500))
    if img_fov:
        pc_velo = get_lidar_in_image_fov(pc_velo, calib, 0, 0,
            img_width, img_height)
        print(('FOV point num: ', pc_velo.shape[0]))
    draw_lidar(pc_velo, fig=fig)

    for obj in objects:
        if obj.type=='DontCare':continue
        # Draw 3d bounding box
        box3d_pts_2d, box3d_pts_3d = utils.compute_box_3d(obj, calib.P) 
        box3d_pts_3d_velo = calib.project_rect_to_velo(box3d_pts_3d)
        # Draw heading arrow
        ori3d_pts_2d, ori3d_pts_3d = utils.compute_orientation_3d(obj, calib.P)
        ori3d_pts_3d_velo = calib.project_rect_to_velo(ori3d_pts_3d)
        x1,y1,z1 = ori3d_pts_3d_velo[0,:]
github enthought / mayavi / examples / mayavi / interactive / mlab_visual.py View on Github external
The `@animate` decorator ( :func:`mayavi.mlab.animate` ) is
detailed on section :ref:`animating_a_visualization`.

If you want to modify the data plotted by the mlab (as in the
`mlab.test_plot3d()` call) to create an animation, please see section
:ref:`mlab-animating-data`.

"""
# Author: Prabhu Ramachandran 
# Copyright (c) 2009, Enthought, Inc.
# License: BSD Style.

from mayavi import mlab
from tvtk.tools import visual
# Create a figure
f = mlab.figure(size=(500,500))
# Tell visual to use this as the viewer.
visual.set_viewer(f)

# A silly visualization.
mlab.test_plot3d()

# Even sillier animation.
b1 = visual.box()
b2 = visual.box(x=4., color=visual.color.red)
b3 = visual.box(x=-4, color=visual.color.red)
b1.v = 5.0

@mlab.show
@mlab.animate(delay=250)
def anim():
    """Animate the b1 box."""
github enthought / mayavi / mayavi / tools / data_wizards / data_source_factory.py View on Github external
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), )
github xingyul / meteornet / semantic_seg_synthia / data_prep / dbg_view.py View on Github external
non_lane_rgb = rgb[semantic != 12]
    non_lane_pc = pc[semantic != 12]

    for i, p in enumerate(lane_pc):
        dist = np.linalg.norm(non_lane_pc - p, axis=-1)
        top_non_lane_idx = np.argsort(dist)[:5]
        print(lane_rgb[i])
        print(non_lane_rgb[top_non_lane_idx])
        print('')

print(pc.shape)

label = class_mapping.index_to_label_vec_func(semantic)

point_size = 0.2
mlab.figure(bgcolor=(1,1,1))
for i in range(12):
    pc_sem = pc[label == i]
    color = class_mapping.index_to_color[class_mapping.label_to_index[i]]

    mlab.points3d(pc_sem[:,0], pc_sem[:,1], pc_sem[:,2], scale_factor=point_size, color=(color[0]/255,color[1]/255,color[2]/255))
input()

f.write('{} {} {} {} {} {}\n'.format(center[0], center[1], center[2], 1, 1, -1))

for i in range(pc.shape[0]):
    p = pc[i]
    color = 2 * rgb[i] - 1
    semantic_color = class_mapping.index_to_color[semantic[i]] / 255.
    ##### write color
    f.write('{} {} {} {} {} {}\n'.format(p[0], p[1], p[2], color[0], color[1], color[2]))
    # f.write('{} {} {} {} {} {}\n'.format(p[0], p[1], p[2], semantic_color[0], semantic_color[1], semantic_color[2]))
github jeffmahler / GPIS / src / grasp_selection / tabletop_object_registration.py View on Github external
t_stp_stp_p = source_x0_closest - target_x0_closest
            t_stp_stp_p[2] = source_x0_highest[2] - min(target_x0_highest[2] - config['table_surface_tol'], table_x0[2])

            T_align_closest = stf.SimilarityTransform3D(pose=tfx.pose(np.eye(3), t_stp_stp_p), from_frame='stp', to_frame='stp')
            target_object_points = T_align_closest.apply(target_object_points.T).T
            target_object_normals = T_align_closest.apply(target_object_normals.T, direction=True).T            
            T_stp_stp_p = T_align_closest.dot(T_stp_stp_p)

            # display the points relative to one another
            if debug:
                subsample_inds3 = np.arange(orig_source_object_points.shape[0])[::10]
                subsample_inds2 = np.arange(source_object_points.shape[0])[::10]
                subsample_inds = np.arange(target_object_points.shape[0])[::10]
                T_table_world = stf.SimilarityTransform3D(pose=tfx.pose(np.eye(4)), from_frame='world', to_frame='table')
                mlab.figure()                
                #mlab.points3d(orig_source_object_points[subsample_inds3,0], orig_source_object_points[subsample_inds3,1], orig_source_object_points[subsample_inds3,2], color=(1,0,1), scale_factor = 0.005)
                mlab.points3d(source_object_points[subsample_inds2,0], source_object_points[subsample_inds2,1], source_object_points[subsample_inds2,2], color=(1,0,0), scale_factor = 0.005)
                mlab.points3d(target_object_points[subsample_inds,0], target_object_points[subsample_inds,1], target_object_points[subsample_inds,2], color=(0, 1,0), scale_factor = 0.005)
                #mlab.points3d(x0_table[0], x0_table[1], x0_table[2], color=(1,1,0), scale_factor = 0.015)
                #mlab.points3d(source_x0_closest[0], source_x0_closest[1], source_x0_closest[2], color=(1,0,1), scale_factor = 0.025)
                #mlab.points3d(target_x0_closest[0], target_x0_closest[1], target_x0_closest[2], color=(0,0,1), scale_factor = 0.025)
                mlab.points3d(0,0,0, color=(1, 1,1), scale_factor = 0.03)

                cam_axis_line = np.array([np.zeros(3), -0.2 * T_stp_camera.rotation[:,2]])
                mlab.plot3d(cam_axis_line[:,0], cam_axis_line[:,1], cam_axis_line[:,2], color=(1,1,1), tube_radius=0.0025)

                #cam_axis_line = np.array([target_x0_closest, target_x0_closest + t_stp_stp_p])
                #mlab.plot3d(cam_axis_line[:,0], cam_axis_line[:,1], cam_axis_line[:,2], color=(0,0,0), tube_radius=0.0025)

                """
                t = 1e-2