2
The main executable file for the zoom_plot demo.
4
Right-click and drag on the upper plot to select a region to view in detail
5
in the lower plot. The selected region can be moved around by dragging,
6
or resized by clicking on one of its edges and dragging.
8
# Standard library imports
11
# Major library imports
12
from numpy import amin, amax, arange, searchsorted, sin, pi, linspace
14
from enthought.enable.example_support import DemoFrame, demo_main
17
from enthought.enable.api import Component, ComponentEditor, Window
18
from enthought.traits.api import HasTraits, Instance
19
from enthought.traits.ui.api import Item, Group, View
20
from enthought.util.resource import find_resource
23
from enthought.chaco.api import SimplePlotFrame, VPlotContainer
24
from enthought.chaco.tools.api import RangeSelection
27
from grid_plot_factory import create_gridded_line_plot
28
from zoom_overlay import ZoomOverlay
30
sample_path = os.path.join('examples','data','sample.wav')
31
alt_path = os.path.join('..','data','sample.wav')
32
fname = find_resource('Chaco', sample_path, alt_path=alt_path,
36
def read_music_data():
37
from wav_to_numeric import wav_to_numeric
38
index, data = wav_to_numeric(fname)
39
return index[:numpts], data[:numpts]
41
def create_zoomed_plot():
43
x,y = read_music_data()
45
x = linspace(-10*pi, 10*pi, numpts)
48
main_plot = create_gridded_line_plot(x,y)
49
zoom_plot = create_gridded_line_plot(x,y)
51
outer_container = VPlotContainer(padding=30,
54
stack_order='top_to_bottom',
58
outer_container.add(main_plot)
59
outer_container.add(zoom_plot)
61
main_plot.controller = RangeSelection(main_plot)
63
zoom_overlay = ZoomOverlay(source=main_plot, destination=zoom_plot)
64
outer_container.overlays.append(zoom_overlay)
66
return outer_container
68
#===============================================================================
69
# Attributes to use for the plot view.
73
#===============================================================================
74
# # Demo class that is used by the demo.py application.
75
#===============================================================================
76
class Demo(HasTraits):
77
plot = Instance(Component)
81
Item('plot', editor=ComponentEditor(size=size),
83
orientation = "vertical"),
84
resizable=True, title=title,
85
width=size[0], height=size[1]
88
def _plot_default(self):
89
return create_zoomed_plot()
93
#===============================================================================
94
# Stand-alone frame to display the plot.
95
#===============================================================================
96
class PlotFrame(DemoFrame):
98
def _create_window(self):
99
# Return a window containing our plots
100
return Window(self, -1, component=create_zoomed_plot())
102
if __name__ == "__main__":
103
demo_main(PlotFrame, size=size, title=title)