How to use the mayavi.mlab.savefig 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 StructuralNeurobiologyLab / SyConn / syconn_deprecated / utils / illustration.py View on Github external
def write_img2png(nml_path, filename='mayavi_img', mag=5):
    """Writes plotted mayavi image to .png at head folder of path with
    supplement

    Parameters
    ----------
    nml_path : string
        path for output file
    filename : str
        filename
    mag : int
        resolution of image
    """
    head, tail = os.path.split(nml_path)
    img_path = head+"/"+filename+".png"
    mlab.savefig(img_path, magnification=mag)
    mlab.close()
    print "Writing image to %s." % img_path
github jeffmahler / GPIS / src / grasp_selection / MABSingleObjectObjective.py View on Github external
mv.clf()
            MayaviVisualizer.mv_plot_table(T_table_world, d=table_extent)
            MayaviVisualizer.mv_plot_pose(T_world, alpha=alpha, tube_radius=tube_radius, center_scale=center_scale)
            MayaviVisualizer.mv_plot_pose(T_gripper_world, alpha=alpha, tube_radius=tube_radius, center_scale=center_scale)
            MayaviVisualizer.mv_plot_pose(T_obj_world, alpha=alpha, tube_radius=tube_radius, center_scale=center_scale)
            MayaviVisualizer.mv_plot_pose(T_camera_world, alpha=alpha, tube_radius=tube_radius, center_scale=center_scale)
            MayaviVisualizer.mv_plot_mesh(object_mesh, T_obj_world)
            MayaviVisualizer.mv_plot_point_cloud(cb_points_camera, T_world_camera, color=(1,1,0))

            delta_view = 360.0 / num_grasp_views
            mv.view(distance=cam_dist)
            for j in range(num_grasp_views):
                az = j * delta_view
                mv.view(azimuth=az)
                figname = 'estimated_scene_view_%d.png' %(j)                
                mv.savefig(os.path.join(logging_dir, figname))

            # execute the grasp
            logging.info('Executing grasp')
            grasp_tf = T_gripper_world.inverse()
            self.ctrl.do_grasp(grasp_tf)
            while not self.ctrl._izzy.is_action_complete():
                time.sleep(0.01)
            if debug:
                self.ctrl.plot_approach_angle()
    
            # record states
            current_state, _ = self.ctrl.getState()
            target_pose = DexRobotIzzy.IZZY_LOCAL_T * grasp_tf.pose
            target_pose.frame = DexConstants.IZZY_LOCAL_FRAME
            target_state = DexRobotIzzy.pose_to_state(target_pose, current_state)
            high_state = current_state.copy().set_arm_elev(lift_height)
github martinling / imusim / imusim / visualisation / video.py View on Github external
figure = mlab.gcf()
    if resolution is not None:
        originalResolution = figure.scene.get_size()
        figure.scene.set_size(resolution)
    figure.scene.off_screen_rendering = True
    figure.scene.disable_render = True

    frameTimes = np.arange(tMin, tMax, 1.0/framerate)

    try:
        imageDir = tempfile.mkdtemp()
        for f,t in enumerate(frameTimes):
            for r in renderers:
                r.renderUpdate(t)
            framefile = os.path.join(imageDir, '%06d.png'%(f))
            mlab.savefig(framefile, size=resolution)
            assert os.path.exists(framefile)

        retval = subprocess.call(['ffmpeg', '-f','image2', '-r', str(framerate),
                '-i', '%s'%os.path.join(imageDir,'%06d.png'), '-sameq',
                filename, '-pass','2'])
    finally:
        shutil.rmtree(imageDir)
        figure.scene.disable_render = False
        figure.scene.off_screen_rendering = False
        if resolution is not None:
            figure.scene.set_size(originalResolution)
github PytLab / VASPy / vaspy / electro.py View on Github external
x, y = np.ogrid[s]
        mx, my = np.mgrid[s]
        #use cubic 2d interpolation
        interpfunc = interp2d(x, y, z, kind='cubic')
        newx = np.linspace(0, ndim0, 600)
        newy = np.linspace(0, ndim1, 600)
        newz = interpfunc(newx, newy)
        #mlab
        face = mlab.surf(newx, newy, newz, warp_scale=2)
        mlab.axes(xlabel='x', ylabel='y', zlabel='z')
        mlab.outline(face)
        #save or show
        if show_mode == 'show':
            mlab.show()
        elif show_mode == 'save':
            mlab.savefig('mlab_contour3d.png')
        else:
            raise ValueError('Unrecognized show mode parameter : ' +
                             show_mode)

        return
github mattions / neuronvisio / neuronvisio / controls.py View on Github external
indx_stop = None
        if time_stop:
            indx_stop = t.indwhere("==", time_stop)
        else:
            indx_stop = len(t)
        
        if not os.path.exists(saving_dir):
            os.mkdir(saving_dir)
            
        png_format = "%09d.png"
        for i in range(int(indx_start), int(indx_stop)):
            
            figure_filename_animation = png_format %(i - indx_start)
            logger.debug( figure_filename_animation)
            self.sync_visio_3d(i)
            mlab.savefig(os.path.join(saving_dir, figure_filename_animation))
        
        logger.info("files created in %s" %saving_dir)
        logger.info("To create a video run:")
        logger.info("ffmpeg -f image2 -r 10 -i %s -sameq anim.mov -pass 2" %png_format)
github hplgit / fdm-book / doc / .src / chapters / wave / src-wave / wave2D_u0 / wave2D_u0.py View on Github external
mlab.colorbar(object=None, title=None,
                          orientation='horizontal',
                          nb_labels=None, nb_colors=None,
                          label_fmt=None)
            mlab.title('Gaussian t=%g' % t[n])
            mlab.view(142, -72, 50)
            f = mlab.gcf()
            camera = f.scene.camera
            camera.yaw(0)

        if plot_method > 0:
            time.sleep(0) # pause between frames
            if save_plot:
                filename = 'tmp_%04d.png' % n
		if plot_method == 4:
                    mlab.savefig(filename)  # time consuming!
		elif plot_method in (1,2):
                    st.savefig(filename)  # time consuming!
github QijingZheng / VaspPoscarMayavi / mview.py View on Github external
p_T[0::2,:] = p_A
        bond_A = mlab.plot3d(p_T[:,0], p_T[:,1], p_T[:,2],
                    tube_radius=0.1, color=A_color)
        bond_A.mlab_source.dataset.lines = bond_connectivity
        # plot the second half of the bond: M-B
        p_T[0::2,:] = p_B
        bond_B = mlab.plot3d(p_T[:,0], p_T[:,1], p_T[:,2],
                    tube_radius=0.1, color=B_color)
        bond_B.mlab_source.dataset.lines = bond_connectivity

    # all_times.append(time.time())
    # print(np.diff(all_times))

    mlab.orientation_axes()
    if quiet:
        mlab.savefig(figname)
    else:
        mlab.show()
github WISDEM / WISDEM / wisdem / floatingse / instance / floating_instance.py View on Github external
def set_figure(self, fig, fname=None):
        from mayavi import mlab
        #ax.set_aspect('equal')
        #set_axes_equal(ax)
        #ax.autoscale_view(tight=True)
        #ax.set_xlim([-125, 125])
        #ax.set_ylim([-125, 125])
        #ax.set_zlim([-220, 30])
        #plt.axis('off')
        #plt.show()
        #mlab.move([-517.16728532, -87.0711504, 5.60826224], [1.35691603e+01, -2.84217094e-14, -1.06547500e+02])
        #mlab.view(-170.68320804213343, 78.220729198686854, 549.40101471336777, [1.35691603e+01,  0.0, -1.06547500e+02])
        if not fname is None: mlab.savefig(fname, figure=fig)
        mlab.show(stop=True)
github sphinx-gallery / sphinx-gallery / sphinx_gallery / gen_rst.py View on Github external
kwargs[attr] = fig_attr

        current_fig = image_path.format(fig_count + fig_mngr.num)
        fig.savefig(current_fig, **kwargs)
        figure_list.append(current_fig)

    if gallery_conf.get('find_mayavi_figures', False):
        from mayavi import mlab
        e = mlab.get_engine()
        last_matplotlib_fig_num = fig_count + len(figure_list)
        total_fig_num = last_matplotlib_fig_num + len(e.scenes)
        mayavi_fig_nums = range(last_matplotlib_fig_num + 1, total_fig_num + 1)

        for scene, mayavi_fig_num in zip(e.scenes, mayavi_fig_nums):
            current_fig = image_path.format(mayavi_fig_num)
            mlab.savefig(current_fig, figure=scene)
            # make sure the image is not too large
            scale_image(current_fig, current_fig, 850, 999)
            figure_list.append(current_fig)
        mlab.close(all=True)

    # Depending on whether we have one or more figures, we're using a
    # horizontal list or a single rst call to 'image'.
    images_rst = ""
    if len(figure_list) == 1:
        figure_name = figure_list[0]
        images_rst = SINGLE_IMAGE % figure_name.lstrip('/')
    elif len(figure_list) > 1:
        images_rst = HLIST_HEADER
        for figure_name in figure_list:
            images_rst += HLIST_IMAGE_TEMPLATE % figure_name.lstrip('/')
github LTS5 / connectomeviewer / scratch / activation_movie.py View on Github external
# Change the opacity function
from tvtk.util.ctf import PiecewiseFunction

shell_size = .1
otf = PiecewiseFunction()
otf.add_point(0, 0)
otf.add_point((.5-shell_size)*anat_vmax, 0.)
# If black background, use 0.2, if white, use .15
otf.add_point(.5*anat_vmax, 0.2)
otf.add_point((.5+shell_size)*anat_vmax, 0.)
otf.add_point(anat_vmax, 0)
vol._volume_property.set_scalar_opacity(otf)
vol.update_ctf = True

mlab.view(25, 70, 310, (1.3, -16.1, 3.27))
mlab.savefig('glass_brain.png', size=(960/REDUCE, 768/REDUCE))

################################################################################
# Render activation
filenames = sorted(glob.glob(
    '/volatile/varoquau/data/data/subject1/functional/fMRI/session1/swfga*.hdr'
    ))


def load_data(filenames):
    mask      = mask_utils.compute_mask_files(filenames)
    series, _ = mask_utils.series_from_mask([filenames, ], mask)
    series    = series.squeeze()
    series -= series.mean(axis=-1)[:, np.newaxis]
    std = series.std(axis=-1)
    std[std==0] = 1
    series /= std[:, np.newaxis]