~ubuntu-branches/ubuntu/utopic/python-chaco/utopic

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2014-06-01 17:04:08 UTC
  • mfrom: (7.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20140601170408-m86xvdjd83a4qon0
Tags: 4.4.1-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
 - Let the binary-predeb target work on the usr/lib/python* directory
   as we don't have usr/share/pyshared anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
from numpy import linspace, sin
3
 
 
4
 
from chaco.api import ArrayPlotData, Plot
5
 
from chaco.tools.api import PanTool, ZoomTool
6
 
from enable.component_editor import ComponentEditor
7
 
from traits.api import Enum, HasTraits, Instance
8
 
from traitsui.api import Item, View
9
 
 
10
 
class PlotEditor(HasTraits):
11
 
 
12
 
    plot = Instance(Plot)
13
 
    plot_type = Enum("scatter", "line")
14
 
    orientation = Enum("horizontal", "vertical")
15
 
    traits_view = View(Item('orientation', label="Orientation"),
16
 
                       Item('plot', editor=ComponentEditor(), show_label=False),
17
 
                       width=500, height=500, resizable=True,
18
 
                       title="Chaco Plot")
19
 
 
20
 
    def __init__(self, *args, **kw):
21
 
        HasTraits.__init__(self, *args, **kw)
22
 
        # Create the data and the PlotData object
23
 
        x = linspace(-14, 14, 100)
24
 
        y = sin(x) * x**3
25
 
        plotdata = ArrayPlotData(x = x, y = y)
26
 
        # Create the scatter plot
27
 
        plot = Plot(plotdata)
28
 
        plot.plot(("x", "y"), type=self.plot_type, color="blue")
29
 
        plot.tools.append(PanTool(plot))
30
 
        plot.tools.append(ZoomTool(plot))
31
 
        self.plot = plot
32
 
 
33
 
    def _orientation_changed(self):
34
 
        if self.orientation == "vertical":
35
 
            self.plot.orientation = "v"
36
 
        else:
37
 
            self.plot.orientation = "h"
38
 
 
39
 
if __name__ == "__main__":
40
 
    # Create the two plots
41
 
    scatter = PlotEditor(plot_type = "scatter")
42
 
    line = PlotEditor(plot_type = "line")
43
 
    # Hook up their ranges
44
 
    scatter.plot.range2d = line.plot.range2d
45
 
    # Bring up both plots by calling edit_traits().  (We call configure_traits()
46
 
    # on the second one so that the application main loop stays running.)
47
 
    line.edit_traits()
48
 
    scatter.configure_traits()
49