~ubuntu-branches/ubuntu/precise/python-chaco/precise

« back to all changes in this revision

Viewing changes to examples/tutorials/scipy2008/data_chooser.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2008-12-29 02:34:05 UTC
  • Revision ID: james.westby@ubuntu.com-20081229023405-x7i4kp9mdxzmdnvu
Tags: upstream-3.0.1
ImportĀ upstreamĀ versionĀ 3.0.1

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 enthought.chaco.api import ArrayPlotData, Plot
 
6
from enthought.enable.component_editor import ComponentEditor
 
7
from enthought.traits.api import Dict, Enum, HasTraits, Instance
 
8
from enthought.traits.ui.api import Item, View
 
9
 
 
10
class DataChooser(HasTraits):
 
11
 
 
12
    plot = Instance(Plot)
 
13
    data_name = Enum("jn0", "jn1", "jn2")
 
14
    traits_view = View(Item('data_name', label="Y data"),
 
15
                       Item('plot', editor=ComponentEditor(), show_label=False), 
 
16
                       width=800, height=600, resizable=True,
 
17
                       title="Data Chooser")
 
18
 
 
19
    def __init__(self):
 
20
        x = linspace(-5, 10, 100)
 
21
        self.data = {"jn0": jn(0, x),
 
22
                     "jn1": jn(1, x),
 
23
                     "jn2": jn(2, x)}
 
24
 
 
25
        # Create the data and the PlotData object
 
26
        self.plotdata = ArrayPlotData(x=x, y=self.data["jn0"])
 
27
 
 
28
        # Create a Plot and associate it with the PlotData
 
29
        plot = Plot(self.plotdata)
 
30
        # Create a line plot in the Plot
 
31
        plot.plot(("x", "y"), type="line", color="blue")
 
32
        self.plot = plot
 
33
 
 
34
    def _data_name_changed(self, old, new):
 
35
        self.plotdata.set_data("y", self.data[self.data_name])
 
36
 
 
37
 
 
38
if __name__ == "__main__":
 
39
    DataChooser().configure_traits()
 
40