3
A modification of updating_plot4.py, except now all the plots are transparent,
4
and the three horizontally oriented plots have linked data views, while
5
the vertical plots are all independent.
8
# Major library imports
10
from numpy import arange, fabs, pi, sin
11
from scipy.special import jn
13
# Enthought library imports
14
from enthought.enable.api import Window
15
from enthought.enable.example_support import DemoFrame, demo_main
16
from enthought.traits.api import false, HasTraits
19
from enthought.chaco.api import *
20
from enthought.chaco.tools.api import MoveTool, PanTool, SimpleZoom
23
COLOR_PALETTE = ("mediumslateblue", "maroon", "darkgreen", "goldenrod",
24
"purple", "indianred")
28
class AnimatedPlot(HasTraits):
29
def __init__(self, x, y, color="blue", bgcolor="none", orientation="h"):
31
if type(x) == ArrayDataSource:
32
self.x_values = x.get_data()[:]
33
plot = create_line_plot((x, self.y_values), color=color,
34
bgcolor=bgcolor, add_grid=True, add_axis=True,
35
orientation=orientation)
38
plot = create_line_plot((self.x_values,self.y_values), color=color,
39
bgcolor=bgcolor, add_grid=True, add_axis=True,
40
orientation=orientation)
43
plot.bounds = [PLOT_SIZE, PLOT_SIZE]
44
plot.unified_draw = True
46
plot.tools.append(PanTool(plot, drag_button="right"))
47
plot.tools.append(MoveTool(plot))
48
plot.overlays.append(SimpleZoom(plot, tool_mode="box", always_on=False))
51
self.numpoints = len(self.x_values)
52
self.current_index = self.numpoints/2
56
if self.current_index <= self.numpoints/3:
58
elif self.current_index == self.numpoints:
60
self.current_index += self.increment
61
if self.current_index > self.numpoints:
62
self.current_index = self.numpoints
63
self.plot.index.set_data(self.x_values[:self.current_index])
64
self.plot.value.set_data(self.y_values[:self.current_index])
65
self.plot.request_redraw()
68
class PlotFrame(DemoFrame):
70
def _create_data(self):
71
values = [jn(i, x) for i in range(10)]
73
def _create_window(self):
77
x = arange(low, high, (high-low)/numpoints)
78
container = OverlayPlotContainer(bgcolor="lightgray")
83
self.animated_plots = []
84
for i, color in enumerate(COLOR_PALETTE):
86
animated_plot = AnimatedPlot(x, jn(i,x), color)
87
plot = animated_plot.plot
88
common_index = plot.index
89
index_range = plot.index_mapper.range
90
value_range = plot.value_mapper.range
92
animated_plot = AnimatedPlot(common_index, jn(i,x), color)
93
plot = animated_plot.plot
94
plot.index_mapper.range = index_range
95
plot.value_mapper.range = value_range
97
animated_plot = AnimatedPlot(x, jn(i,x), color, orientation="v")
98
plot = animated_plot.plot
101
self.animated_plots.append(animated_plot)
104
for i, a_plot in enumerate(self.animated_plots):
105
a_plot.plot.position = [50 + (i%3)*(PLOT_SIZE+50), 50 + (i//3)*(PLOT_SIZE+50)]
108
# Set the timer to generate events to us
110
self.timer = wx.Timer(self, timerId)
111
self.Bind(wx.EVT_TIMER, self.onTimer, id=timerId)
112
self.timer.Start(100.0, wx.TIMER_CONTINUOUS)
114
self.container = container
115
return Window(self, -1, component=container)
117
def onTimer(self, event):
118
for plot in self.animated_plots:
123
if __name__ == "__main__":
124
demo_main(PlotFrame, size=(1000,800), title="Updating line plot")