4
from enthought.chaco.api import Plot, ArrayPlotData
5
from enthought.chaco.layers.api import ErrorLayer, WarningLayer, StatusLayer
6
from enthought.enable.component_editor import ComponentEditor
7
from enthought.traits.api import HasTraits, Instance, Button
8
from enthought.traits.ui.api import Item, View, HGroup
10
class MyPlot(HasTraits):
11
""" Displays a plot with a few buttons to control which overlay
15
status_overlay = Instance(StatusLayer)
17
error_button = Button('Error')
18
warn_button = Button('Warning')
19
no_problem_button = Button('No problem')
21
traits_view = View( HGroup(Item('error_button', show_label=False),
22
Item('warn_button', show_label=False),
23
Item('no_problem_button', show_label=False)),
24
Item('plot', editor=ComponentEditor(), show_label=False),
27
def __init__(self, index, data_series, **kw):
28
super(MyPlot, self).__init__(**kw)
30
plot_data = ArrayPlotData(index=index)
31
plot_data.set_data('data_series', data_series)
32
self.plot = Plot(plot_data)
33
self.plot.plot(('index', 'data_series'))
35
def _error_button_fired(self, event):
36
""" removes the old overlay and replaces it with
41
self.status_overlay = ErrorLayer(component=self.plot,
42
align='ul', scale_factor=0.25)
43
self.plot.overlays.append(self.status_overlay)
45
self.plot.request_redraw()
47
def _warn_button_fired(self, event):
48
""" removes the old overlay and replaces it with
53
self.status_overlay = WarningLayer(component=self.plot,
54
align='ur', scale_factor=0.25)
55
self.plot.overlays.append(self.status_overlay)
57
self.plot.request_redraw()
59
def _no_problem_button_fired(self, event):
60
""" removes the old overlay
63
self.plot.request_redraw()
65
def clear_status(self):
66
if self.status_overlay in self.plot.overlays:
67
# fade_out will remove the overlay when its done
68
self.status_overlay.fade_out()
70
index = numpy.array([1,2,3,4,5])
71
data_series = index**2
73
my_plot = MyPlot(index, data_series)
74
my_plot.configure_traits()