3
A modification of updating_plot.py to show 6 different plots whose data
6
Click and drag any of the plots to reposition them.
7
Right-click and drag inside the plots to pan them.
8
Mousewheel up and down to zoom. Zoom box is availble (see
9
description in simple_line.py).
12
# Major library imports
14
from numpy import arange
15
from scipy.special import jn
17
# Enthought library imports
18
from enable.api import Window
19
from enable.example_support import DemoFrame, demo_main
20
from traits.api import HasTraits
23
from chaco.api import *
24
from chaco.tools.api import MoveTool, PanTool, ZoomTool
26
COLOR_PALETTE = ("mediumslateblue", "maroon", "darkgreen", "goldenrod",
27
"purple", "indianred")
31
class AnimatedPlot(HasTraits):
32
def __init__(self, x, y, color="blue", bgcolor="white"):
35
self.numpoints = len(self.x_values)
37
plot = create_line_plot((self.x_values,self.y_values), color=color, bgcolor=bgcolor,
38
add_grid=True, add_axis=True)
40
plot.bounds = [PLOT_SIZE, PLOT_SIZE]
42
plot.tools.append(PanTool(plot, drag_button="right"))
43
plot.tools.append(MoveTool(plot))
44
plot.overlays.append(ZoomTool(plot, tool_mode="box", always_on=False))
46
plot.unified_draw = True
49
self.current_index = self.numpoints/2
53
if self.current_index <= self.numpoints/3:
55
elif self.current_index == self.numpoints:
57
self.current_index += self.increment
58
if self.current_index > self.numpoints:
59
self.current_index = self.numpoints
60
self.plot.index.set_data(self.x_values[:self.current_index])
61
self.plot.value.set_data(self.y_values[:self.current_index])
62
self.plot.request_redraw()
65
class PlotFrame(DemoFrame):
67
def _create_data(self):
68
values = [jn(i, x) for i in range(10)]
70
def _create_window(self):
74
x = arange(low, high, (high-low)/numpoints)
75
container = OverlayPlotContainer(bgcolor="lightgray")
77
self.animated_plots = []
78
for i, color in enumerate(COLOR_PALETTE):
79
animated_plot = AnimatedPlot(x, jn(i,x), color)
80
container.add(animated_plot.plot)
81
self.animated_plots.append(animated_plot)
83
for i, a_plot in enumerate(self.animated_plots):
84
a_plot.plot.position = [50 + (i%3)*(PLOT_SIZE+50), 50 + (i//3)*(PLOT_SIZE+50)]
86
# Set the timer to generate events to us
88
self.timer = wx.Timer(self, timerId)
89
self.Bind(wx.EVT_TIMER, self.onTimer, id=timerId)
90
self.timer.Start(100.0, wx.TIMER_CONTINUOUS)
92
self.container = container
93
return Window(self, -1, component=container)
95
def onTimer(self, event):
96
for plot in self.animated_plots:
101
if __name__ == "__main__":
102
demo_main(PlotFrame, size=(1000,600), title="Updating line plot")