3
from chaco.api import LinearMapper, Plot, ArrayDataSource, DataRange1D
4
from chaco.multi_array_data_source import MultiArrayDataSource
5
from chaco.multi_line_plot import MultiLinePlot
6
from enable.api import ComponentEditor
7
from traits.api import Instance, HasTraits
8
from traitsui.api import View, Item
10
class MyPlot(HasTraits):
11
""" Displays a plot with a few buttons to control which overlay
16
traits_view = View(Item('plot', editor=ComponentEditor(), show_label=False),
19
def __init__(self, x_index, y_index, data, **kw):
20
super(MyPlot, self).__init__(**kw)
22
# Create the data source for the MultiLinePlot.
23
ds = MultiArrayDataSource(data=data)
25
xs = ArrayDataSource(x_index, sort_order='ascending')
26
xrange = DataRange1D()
29
ys = ArrayDataSource(y_index, sort_order='ascending')
30
yrange = DataRange1D()
36
index_mapper = LinearMapper(range=xrange),
37
value_mapper = LinearMapper(range=yrange),
39
global_max = np.nanmax(data),
40
global_min = np.nanmin(data),
47
x_index = np.arange(0,100, 1)
48
y_index = np.arange(0,1000, 10)
49
data = np.sin(np.arange(0,x_index.size*y_index.size))
50
# add a random chunk of nan values
51
data[1532:1588] = np.nan
52
data = data.reshape(x_index.size, y_index.size)
54
my_plot = MyPlot(x_index, y_index, data)
55
my_plot.configure_traits()