{ "metadata": { "signature": "sha256:ee715a8da2e8ee8549c09debe60ef2a2ccafa517162e5f1348be3912d6917227" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Mayavi surf\n", "===========\n", "\n", "If you want to plot a surface representing a matrix by elevation and\n", "colour of its points you have to transform the matrix data in a 3D data\n", "that !MayaVi2 can understand. [:Cookbook/MayaVi/mlab:mlab] knows how to\n", "do this, but it does not have the nice user interface of !MayaVi2. Here\n", "is a script that create a !SurfRegular object using mlab, and then loads\n", "it in !MayaVi2. A more detailed version of this script is given in the\n", "examples pages [:Cookbook/MayaVi/Examples]." ] }, { "cell_type": "code", "collapsed": false, "input": [ "import numpy\n", "def f(x, y):\n", " return numpy.sin(x*y)/(x*y)\n", "x = numpy.arange(-7., 7.05, 0.1)\n", "y = numpy.arange(-5., 5.05, 0.05)\n", "from enthought.tvtk.tools import mlab\n", "s = mlab.SurfRegular(x, y, f)\n", "from enthought.mayavi.sources.vtk_data_source import VTKDataSource\n", "d = VTKDataSource()\n", "d.data = s.data\n", "mayavi.add_source(d)\n", "from enthought.mayavi.filters.warp_scalar import WarpScalar\n", "w = WarpScalar()\n", "mayavi.add_filter(w)\n", "from enthought.mayavi.modules.outline import Outline\n", "from enthought.mayavi.modules.surface import Surface\n", "o = Outline()\n", "s = Surface()\n", "mayavi.add_module(o)\n", "mayavi.add_module(s)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can run this script by running \"mayavi2 -n -x script.py\", loading it through the menu (File -> Open File), and pressing Ctrl+R, or entering \"execfile('script.py') in the python shell." ] } ], "metadata": {} } ] }