3
A modification of updating_plot3.py.
5
Three of the plots are now oriented vertically, but the dataspace of all
6
6 plots is still linked. Panning along the X axis of a vertical plot
7
will move the Y axis of one of the horizontally-oriented plots, and vice
11
# Major library imports
13
from numpy import arange
14
from scipy.special import jn
16
# Enthought library imports
17
from enable.api import Window
18
from enable.example_support import DemoFrame, demo_main
19
from traits.api import HasTraits
22
from chaco.api import *
23
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", orientation="h"):
34
if type(x) == ArrayDataSource:
35
self.x_values = x.get_data()[:]
36
plot = create_line_plot((x, self.y_values), color=color,
37
bgcolor=bgcolor, add_grid=True, add_axis=True,
38
orientation=orientation)
41
plot = create_line_plot((self.x_values,self.y_values), color=color,
42
bgcolor=bgcolor, add_grid=True, add_axis=True,
43
orientation=orientation)
46
plot.bounds = [PLOT_SIZE, PLOT_SIZE]
47
plot.unified_draw = True
49
plot.tools.append(PanTool(plot, drag_button="right"))
50
plot.tools.append(MoveTool(plot))
51
plot.overlays.append(ZoomTool(plot, tool_mode="box", always_on=False))
54
self.numpoints = len(self.x_values)
55
self.current_index = self.numpoints/2
59
if self.current_index <= self.numpoints/3:
61
elif self.current_index == self.numpoints:
63
self.current_index += self.increment
64
if self.current_index > self.numpoints:
65
self.current_index = self.numpoints
66
self.plot.index.set_data(self.x_values[:self.current_index])
67
self.plot.value.set_data(self.y_values[:self.current_index])
68
self.plot.request_redraw()
71
class PlotFrame(DemoFrame):
73
def _create_data(self):
74
values = [jn(i, x) for i in range(10)]
76
def _create_window(self):
80
x = arange(low, high, (high-low)/numpoints)
81
container = OverlayPlotContainer(bgcolor="lightgray")
86
self.animated_plots = []
87
for i, color in enumerate(COLOR_PALETTE):
89
animated_plot = AnimatedPlot(x, jn(i,x), color)
90
plot = animated_plot.plot
91
common_index = plot.index
92
index_range = plot.index_mapper.range
93
value_range = plot.value_mapper.range
99
animated_plot = AnimatedPlot(common_index, jn(i,x), color,
100
orientation=orientation)
101
plot = animated_plot.plot
102
plot.index_mapper.range = index_range
103
plot.value_mapper.range = value_range
106
self.animated_plots.append(animated_plot)
109
for i, a_plot in enumerate(self.animated_plots):
110
a_plot.plot.position = [50 + (i%3)*(PLOT_SIZE+50), 50 + (i//3)*(PLOT_SIZE+50)]
113
# Set the timer to generate events to us
115
self.timer = wx.Timer(self, timerId)
116
self.Bind(wx.EVT_TIMER, self.onTimer, id=timerId)
117
self.timer.Start(100.0, wx.TIMER_CONTINUOUS)
119
self.container = container
120
return Window(self, -1, component=container)
122
def onTimer(self, event):
123
for plot in self.animated_plots:
128
if __name__ == "__main__":
129
demo_main(PlotFrame, size=(1000,800), title="Updating line plot")