2
from numpy import linspace, sin
4
from chaco.api import ArrayPlotData, Plot
5
from enable.api import BaseTool
6
from enable.component_editor import ComponentEditor
7
from traits.api import Enum, HasTraits, Instance
8
from traitsui.api import Item, View
10
class CustomTool(BaseTool):
12
event_state = Enum("normal", "mousedown")
14
def normal_mouse_move(self, event):
15
print "Screen:", event.x, event.y
17
def normal_left_down(self, event):
18
self.event_state = "mousedown"
21
def mousedown_mouse_move(self, event):
22
print "Data:", self.component.map_data((event.x, event.y))
24
def mousedown_left_up(self, event):
25
self.event_state = "normal"
29
class ScatterPlot(HasTraits):
33
traits_view = View(Item('plot', editor=ComponentEditor(), show_label=False),
34
width=800, height=600, resizable=True,
37
def _plot_default(self):
38
# Create the data and the PlotData object
39
x = linspace(-14, 14, 100)
41
plotdata = ArrayPlotData(x = x, y = y)
42
# Create a Plot and associate it with the PlotData
44
# Create a scatter plot in the Plot
45
plot.plot(("x", "y"), type="scatter", color="blue")
46
# Add our custom tool to the plot
47
plot.tools.append(CustomTool(plot))
50
#===============================================================================
51
# demo object that is used by the demo.py application.
52
#===============================================================================
54
if __name__ == "__main__":
55
demo.edit_traits(kind="livemodal")