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

« back to all changes in this revision

Viewing changes to examples/demo/multi_line_plot.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
 
import numpy as np
2
 
 
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
9
 
 
10
 
class MyPlot(HasTraits):
11
 
    """ Displays a plot with a few buttons to control which overlay
12
 
        to display
13
 
    """
14
 
    plot = Instance(Plot)
15
 
 
16
 
    traits_view = View(Item('plot', editor=ComponentEditor(), show_label=False),
17
 
                        resizable=True)
18
 
 
19
 
    def __init__(self, x_index, y_index, data, **kw):
20
 
        super(MyPlot, self).__init__(**kw)
21
 
 
22
 
        # Create the data source for the MultiLinePlot.
23
 
        ds = MultiArrayDataSource(data=data)
24
 
 
25
 
        xs = ArrayDataSource(x_index, sort_order='ascending')
26
 
        xrange = DataRange1D()
27
 
        xrange.add(xs)
28
 
 
29
 
        ys = ArrayDataSource(y_index, sort_order='ascending')
30
 
        yrange = DataRange1D()
31
 
        yrange.add(ys)
32
 
 
33
 
        mlp = MultiLinePlot(
34
 
                        index = xs,
35
 
                        yindex = ys,
36
 
                        index_mapper = LinearMapper(range=xrange),
37
 
                        value_mapper = LinearMapper(range=yrange),
38
 
                        value=ds,
39
 
                        global_max = np.nanmax(data),
40
 
                        global_min = np.nanmin(data),
41
 
                        **kw)
42
 
 
43
 
        self.plot = Plot()
44
 
        self.plot.add(mlp)
45
 
 
46
 
 
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)
53
 
 
54
 
my_plot = MyPlot(x_index, y_index, data)
55
 
my_plot.configure_traits()