<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Tips and Tricks — Mayavi2 v2.2.0 documentation</title> <link rel="stylesheet" href="_static/default.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '', VERSION: '2.2.0', COLLAPSE_MODINDEX: false, }; </script> <script type="text/javascript" src="_static/jquery.js"></script> <script type="text/javascript" src="_static/interface.js"></script> <script type="text/javascript" src="_static/doctools.js"></script> <link rel="contents" title="Global table of contents" href="contents.html" /> <link rel="index" title="Global index" href="genindex.html" /> <link rel="search" title="Search" href="search.html" /> <link rel="top" title="Mayavi2 v2.2.0 documentation" href="index.html" /> <link rel="next" title="Miscellaneous" href="misc.html" /> <link rel="prev" title="Creating data for Mayavi" href="data.html" /> </head> <body> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="modindex.html" title="Global Module Index" accesskey="M">modules</a> |</li> <li class="right" > <a href="misc.html" title="Miscellaneous" accesskey="N">next</a> |</li> <li class="right" > <a href="data.html" title="Creating data for Mayavi" accesskey="P">previous</a> |</li> <li><a href="index.html">Mayavi2 v2.2.0 documentation</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section"> <h1 id="tips-and-tricks">Tips and Tricks<a class="headerlink" href="#tips-and-tricks" title="Permalink to this headline">¶</a></h1> <p>Below are a few useful tips and tricks that you may find useful when you use Mayavi2.</p> <div class="section"> <h2 id="customizing-the-mayavi2-ui">Customizing the Mayavi2 UI<a class="headerlink" href="#customizing-the-mayavi2-ui" title="Permalink to this headline">¶</a></h2> <p>See the <tt class="docutils literal"><span class="pre">examples/mayavi_custom_ui.py</span></tt> example that documents and shows how the UI of the <tt class="docutils literal"><span class="pre">mayavi2</span></tt> application can be modified. The module documents how this can be done and provides a simple example.</p> </div> <div class="section"> <h2 id="off-screen-rendering">Off screen rendering<a class="headerlink" href="#off-screen-rendering" title="Permalink to this headline">¶</a></h2> <p>Often you write Mayavi scripts to render a whole batch of images to make an animation or so and find that each time you save an image, Mayavi “raises” the window to make it the active window thus disrupting your work. This is needed since VTK internally grabs the window to make a picture. To get around this behavior you may click on the scene and set the “Off screen rendering” option on. Or from a script:</p> <div class="highlight"><pre><span class="n">mayavi</span><span class="o">.</span><span class="n">engine</span><span class="o">.</span><span class="n">current_scene</span><span class="o">.</span><span class="n">scene</span><span class="o">.</span><span class="n">off_screen_rendering</span> <span class="o">=</span> <span class="bp">True</span> </pre></div> <p>This will stop raising the window. However, this may not be enough. If you are using win32 then off screen rendering should work well out of the box. On Linux and the Mac you will need VTK-5.1 (currently from CVS) to get this working properly.</p> <p>If upgrading VTK is a problem there is another approach for any OS that supports X11. This option should work irrespective of the version of VTK you are using. The idea is to use the virtual framebuffer X server for X11 like so:</p> <blockquote> <ul> <li><p class="first">Make sure you have the <cite>xvfb</cite> package installed.</p> </li> <li><p class="first">Create the virtual framebuffer X server like so:</p> <pre>xvfb :1 -screen 0 1280x1024x24</pre> <p>This creates the display “:1” and creates a screen of size 1280x1024 with 24 bpp. For more options check your <tt class="docutils literal"><span class="pre">xvfb</span></tt> man page.</p> </li> <li><p class="first">Export display to :1 like so (on bash):</p> <pre>$ export DISPLAY=:1</pre> </li> <li><p class="first">Now run your mayavi script. It should run uninterrupted on this X server and produce your saved images.</p> </li> </ul> </blockquote> <p>This probably will have to be fine tuned to suit your taste.</p> <p>Note that if you want to use mayavi without the envisage UI or even a traits UI (i.e. with a pure TVTK window) and do off screen rendering with Python scripts you may be interested in the <tt class="docutils literal"><span class="pre">examples/offscreen.py</span></tt> example. This simple example shows how you can use MayaVi without using Envisage or the MayaVi envisage application and still do off screen rendering.</p> </div> <div class="section"> <h2 id="using-mlab-with-the-full-envisage-ui">Using <tt class="docutils literal"><span class="pre">mlab</span></tt> with the full envisage UI<a class="headerlink" href="#using-mlab-with-the-full-envisage-ui" title="Permalink to this headline">¶</a></h2> <p>Sometimes it is convenient to write an mlab script but still use the full envisage application so you can click on the menus and use other modules etc. To do this you may do the following before you create an mlab figure:</p> <div class="highlight"><pre><span class="k">from</span> <span class="nn">enthought.mayavi</span> <span class="k">import</span> <span class="n">mlab</span> <span class="n">mlab</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">backend</span> <span class="o">=</span> <span class="s">'envisage'</span> <span class="n">f</span> <span class="o">=</span> <span class="n">mlab</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span> <span class="c"># ...</span> </pre></div> <p>This will give you the full-fledged UI instead of the default simple window.</p> </div> <div class="section"> <h2 id="scripting-mayavi-without-using-envisage">Scripting mayavi without using Envisage<a class="headerlink" href="#scripting-mayavi-without-using-envisage" title="Permalink to this headline">¶</a></h2> <p>The example <tt class="docutils literal"><span class="pre">examples/standalone.py</span></tt> demonstrates how one can use Mayavi without using Envisage. This is useful when you want to minimize dependencies. <tt class="docutils literal"><span class="pre">examples/offscreen.py</span></tt> demonstrates how to use mayavi without the envisage UI or even a traits UI (i.e. with a pure TVTK window) and do off screen rendering.</p> </div> <div class="section"> <h2 id="embedding-mayavi-in-your-own-traits-ui">Embedding mayavi in your own traits UI<a class="headerlink" href="#embedding-mayavi-in-your-own-traits-ui" title="Permalink to this headline">¶</a></h2> <p>You’ve written your traits based application complete with a nice UI and now you want to do some 3D plotting and embed that UI inside your own UI. This can be easily done. <tt class="docutils literal"><span class="pre">examples/mayavi_traits_ui.py</span></tt> is a fairly comprehensive example that demonstrates how you can embed almost the entire mayavi UI into your traits based UI. <tt class="docutils literal"><span class="pre">examples/mlab_traits_ui.py</span></tt> demonstrates how you can do some simple mlab based visualization.</p> </div> <div class="section"> <h2 id="computing-in-a-thread">Computing in a thread<a class="headerlink" href="#computing-in-a-thread" title="Permalink to this headline">¶</a></h2> <p><tt class="docutils literal"><span class="pre">examples/compute_in_thread.py</span></tt> demonstrates how to visualize a 2D numpy array and visualize it as image data using a few modules. It also shows how one can do a computation in another thread and update the mayavi pipeline once the computation is done. This allows a user to interact with the user interface when the computation is performed in another thread.</p> </div> <div class="section"> <h2 id="polling-a-file-and-auto-updating-mayavi">Polling a file and auto-updating mayavi<a class="headerlink" href="#polling-a-file-and-auto-updating-mayavi" title="Permalink to this headline">¶</a></h2> <p>Sometimes you have a separate computational process that generates data suitable for visualization. You’d like mayavi to visualize the data but automatically update the data when the data file is updated by the computation. This is easily achieved by polling the data file and checking if it has been modified. The <tt class="docutils literal"><span class="pre">examples/poll_file.py</span></tt> demonstrates this. To see it in action will require that you edit the scalar data in the <tt class="docutils literal"><span class="pre">examples/data/heart.vtk</span></tt> data file.</p> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <p class="logo"><img class="logo" src="_static/mayavi-logo.png" alt="Logo"/></p> <h3>Table Of Contents</h3> <ul> <li><a class="reference" href="">Tips and Tricks</a><ul> <li><a class="reference" href="#customizing-the-mayavi2-ui">Customizing the Mayavi2 UI</a></li> <li><a class="reference" href="#off-screen-rendering">Off screen rendering</a></li> <li><a class="reference" href="#using-mlab-with-the-full-envisage-ui">Using <tt class="docutils literal"><span class="pre">mlab</span></tt> with the full envisage UI</a></li> <li><a class="reference" href="#scripting-mayavi-without-using-envisage">Scripting mayavi without using Envisage</a></li> <li><a class="reference" href="#embedding-mayavi-in-your-own-traits-ui">Embedding mayavi in your own traits UI</a></li> <li><a class="reference" href="#computing-in-a-thread">Computing in a thread</a></li> <li><a class="reference" href="#polling-a-file-and-auto-updating-mayavi">Polling a file and auto-updating mayavi</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="data.html" title="previous chapter">Creating data for Mayavi</a></p> <h4>Next topic</h4> <p class="topless"><a href="misc.html" title="next chapter">Miscellaneous</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="_sources/tips.txt">Show Source</a></li> </ul> <h3>Quick search</h3> <form class="search" action="search.html" method="get"> <input type="text" name="q" size="18" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="modindex.html" title="Global Module Index" accesskey="M">modules</a> |</li> <li class="right" > <a href="misc.html" title="Miscellaneous" accesskey="N">next</a> |</li> <li class="right" > <a href="data.html" title="Creating data for Mayavi" accesskey="P">previous</a> |</li> <li><a href="index.html">Mayavi2 v2.2.0 documentation</a> »</li> </ul> </div> <div class="footer"> © Copyright 2008, Prabhu Ramachandran, Gaël Varoquaux. Last updated on Jun 29, 2008. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>. </div> </body> </html>