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

« back to all changes in this revision

Viewing changes to examples/demo/tornado.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
 
""" Tornado plot example from Brennan Williams """
2
 
 
3
 
# Major library imports
4
 
from numpy import linspace, pi, sin, ones
5
 
 
6
 
# Enthought library imports
7
 
from enable.api import Component, ComponentEditor
8
 
from traits.api import HasTraits, Instance
9
 
from traitsui.api import Item, View
10
 
 
11
 
# Chaco imports
12
 
from chaco.api import ArrayDataSource, BarPlot, DataRange1D, LabelAxis, \
13
 
                      LinearMapper, OverlayPlotContainer, PlotAxis
14
 
from chaco.example_support import COLOR_PALETTE
15
 
 
16
 
class PlotExample(HasTraits):
17
 
    plot = Instance(Component)
18
 
 
19
 
    traits_view = View(Item('plot', editor=ComponentEditor(), show_label=False),
20
 
                    resizable=True, title="Tornado Plot",
21
 
                    width=800, height=600
22
 
                    )
23
 
 
24
 
    def _plot_default(self):
25
 
        container = OverlayPlotContainer(bgcolor = "white")
26
 
        plots = self._make_curves()
27
 
        for plot in plots:
28
 
            plot.padding = 60
29
 
            container.add(plot)
30
 
 
31
 
        bottom_axis = PlotAxis(plot, orientation='bottom')
32
 
 
33
 
        label_list=['var a', 'var b', 'var c', 'var d', 'var e', 'var f',
34
 
                    'var g', 'var h', 'var i']
35
 
        vertical_axis = LabelAxis(plot, orientation='left',
36
 
                                title='Categories',
37
 
                                positions = range(1, 10),
38
 
                                labels=label_list)
39
 
        vertical2_axis = LabelAxis(plot, orientation='right',
40
 
                                   positions = range(1, 10),
41
 
                                   labels=label_list)
42
 
 
43
 
        plot.underlays.append(vertical_axis)
44
 
        plot.underlays.append(vertical2_axis)
45
 
        plot.underlays.append(bottom_axis)
46
 
 
47
 
        return container
48
 
 
49
 
    def _get_points(self):
50
 
        index = linspace(pi/4, 3*pi/2, 9)
51
 
        data = sin(index) + 2
52
 
        return (range(1, 10), data)
53
 
 
54
 
    def _make_curves(self):
55
 
        (index_points, value_points) = self._get_points()
56
 
        size = len(index_points)
57
 
 
58
 
        middle_value=2500000.0
59
 
        mid_values=middle_value*ones(size)
60
 
        low_values=mid_values-10000.0*value_points
61
 
        high_values=mid_values+20000.0*value_points
62
 
 
63
 
        idx = ArrayDataSource(index_points)
64
 
        vals = ArrayDataSource(low_values, sort_order="none")
65
 
 
66
 
        idx2 = ArrayDataSource(index_points)
67
 
        vals2 = ArrayDataSource(high_values, sort_order="none")
68
 
 
69
 
        starting_vals = ArrayDataSource(mid_values, sort_order="none")
70
 
 
71
 
        # Create the index range
72
 
        index_range = DataRange1D(idx, low=0.5, high=9.5)
73
 
        index_mapper = LinearMapper(range=index_range)
74
 
 
75
 
        # Create the value range
76
 
        value_range = DataRange1D(vals, vals2, low_setting='auto',
77
 
                                  high_setting='auto', tight_bounds=False)
78
 
        value_mapper = LinearMapper(range=value_range,tight_bounds=False)
79
 
 
80
 
        # Create the plot
81
 
        plot1 = BarPlot(index=idx, value=vals,
82
 
                        value_mapper=value_mapper,
83
 
                        index_mapper=index_mapper,
84
 
                        starting_value=starting_vals,
85
 
                        line_color='black',
86
 
                        orientation='v',
87
 
                        fill_color=tuple(COLOR_PALETTE[6]),
88
 
                        bar_width=0.8, antialias=False)
89
 
 
90
 
        plot2 = BarPlot(index=idx2, value=vals2,
91
 
                        value_mapper=value_mapper,
92
 
                        index_mapper=index_mapper,
93
 
                        starting_value=starting_vals,
94
 
                        line_color='black',
95
 
                        orientation='v',
96
 
                        fill_color=tuple(COLOR_PALETTE[1]),
97
 
                        bar_width=0.8, antialias=False)
98
 
 
99
 
        return [plot1, plot2]
100
 
 
101
 
 
102
 
demo = PlotExample()
103
 
 
104
 
if __name__ == "__main__":
105
 
    demo.configure_traits()