~ubuntu-branches/ubuntu/oneiric/python-chaco/oneiric

« back to all changes in this revision

Viewing changes to examples/demo/vtk/vtk_example.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-07-08 20:38:02 UTC
  • mfrom: (7.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110708203802-5t32e0ldv441yh90
Tags: 4.0.0-1
* New upstream release
* debian/control:
  - Depend on python-traitsui (Closes: #633604)
  - Bump Standards-Version to 3.9.2
* Update debian/watch file
* Remove debian/patches/* -- no longer needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
from numpy import linspace
 
3
from scipy.special import jn
 
4
 
 
5
from tvtk.api import tvtk
 
6
from mayavi import mlab
 
7
from enable.vtk_backend.vtk_window import EnableVTKWindow
 
8
from chaco.api import ArrayPlotData, Plot, OverlayPlotContainer
 
9
from chaco.tools.api import PanTool, ZoomTool, MoveTool
 
10
 
 
11
def main():
 
12
    # Create some x-y data series to plot
 
13
    x = linspace(-2.0, 10.0, 100)
 
14
    pd = ArrayPlotData(index = x)
 
15
    for i in range(5):
 
16
        pd.set_data("y" + str(i), jn(i,x))
 
17
 
 
18
    # Create some line plots of some of the data
 
19
    plot = Plot(pd, bgcolor="none", padding=30, border_visible=True,
 
20
                 overlay_border=True, use_backbuffer=False)
 
21
    plot.legend.visible = True
 
22
    plot.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="auto")
 
23
    plot.plot(("index", "y3"), name="j_3", color="auto")
 
24
    plot.tools.append(PanTool(plot))
 
25
    zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
 
26
    plot.overlays.append(zoom)
 
27
 
 
28
    # Create the mlab test mesh and get references to various parts of the
 
29
    # VTK pipeline
 
30
    f = mlab.figure(size=(600,500))
 
31
    m = mlab.test_mesh()
 
32
    scene = mlab.gcf().scene
 
33
    render_window = scene.render_window
 
34
    renderer = scene.renderer
 
35
    rwi = scene.interactor
 
36
 
 
37
    plot.resizable = ""
 
38
    plot.bounds = [200,200]
 
39
    plot.padding = 25
 
40
    plot.bgcolor = "lightgray"
 
41
    plot.outer_position = [30,30]
 
42
    plot.tools.append(MoveTool(component=plot,drag_button="right"))
 
43
 
 
44
    container = OverlayPlotContainer(bgcolor = "transparent",
 
45
                    fit_window = True)
 
46
    container.add(plot)
 
47
 
 
48
    # Create the Enable Window
 
49
    window = EnableVTKWindow(rwi, renderer,
 
50
            component=container,
 
51
            #istyle_class = tvtk.InteractorStyleSwitch,
 
52
            #istyle_class = tvtk.InteractorStyle,
 
53
            istyle_class = tvtk.InteractorStyleTrackballCamera,
 
54
            bgcolor = "transparent",
 
55
            event_passthrough = True,
 
56
            )
 
57
 
 
58
    mlab.show()
 
59
    return window, render_window
 
60
 
 
61
if __name__=="__main__":
 
62
    main()
 
63