2
from numpy import linspace, sin
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
10
class PlotEditor(HasTraits):
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,
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)
25
plotdata = ArrayPlotData(x = x, y = y)
26
# Create the scatter plot
28
plot.plot(("x", "y"), type=self.plot_type, color="blue")
29
plot.tools.append(PanTool(plot))
30
plot.tools.append(ZoomTool(plot))
33
def _orientation_changed(self):
34
if self.orientation == "vertical":
35
self.plot.orientation = "v"
37
self.plot.orientation = "h"
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.)
48
scatter.configure_traits()