1
""" Tornado plot example from Brennan Williams """
3
# Major library imports
4
from numpy import linspace, pi, sin, ones
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
12
from chaco.api import ArrayDataSource, BarPlot, DataRange1D, LabelAxis, \
13
LinearMapper, OverlayPlotContainer, PlotAxis
14
from chaco.example_support import COLOR_PALETTE
16
class PlotExample(HasTraits):
17
plot = Instance(Component)
19
traits_view = View(Item('plot', editor=ComponentEditor(), show_label=False),
20
resizable=True, title="Tornado Plot",
24
def _plot_default(self):
25
container = OverlayPlotContainer(bgcolor = "white")
26
plots = self._make_curves()
31
bottom_axis = PlotAxis(plot, orientation='bottom')
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',
37
positions = range(1, 10),
39
vertical2_axis = LabelAxis(plot, orientation='right',
40
positions = range(1, 10),
43
plot.underlays.append(vertical_axis)
44
plot.underlays.append(vertical2_axis)
45
plot.underlays.append(bottom_axis)
49
def _get_points(self):
50
index = linspace(pi/4, 3*pi/2, 9)
52
return (range(1, 10), data)
54
def _make_curves(self):
55
(index_points, value_points) = self._get_points()
56
size = len(index_points)
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
63
idx = ArrayDataSource(index_points)
64
vals = ArrayDataSource(low_values, sort_order="none")
66
idx2 = ArrayDataSource(index_points)
67
vals2 = ArrayDataSource(high_values, sort_order="none")
69
starting_vals = ArrayDataSource(mid_values, sort_order="none")
71
# Create the index range
72
index_range = DataRange1D(idx, low=0.5, high=9.5)
73
index_mapper = LinearMapper(range=index_range)
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)
81
plot1 = BarPlot(index=idx, value=vals,
82
value_mapper=value_mapper,
83
index_mapper=index_mapper,
84
starting_value=starting_vals,
87
fill_color=tuple(COLOR_PALETTE[6]),
88
bar_width=0.8, antialias=False)
90
plot2 = BarPlot(index=idx2, value=vals2,
91
value_mapper=value_mapper,
92
index_mapper=index_mapper,
93
starting_value=starting_vals,
96
fill_color=tuple(COLOR_PALETTE[1]),
97
bar_width=0.8, antialias=False)
104
if __name__ == "__main__":
105
demo.configure_traits()