Skip to content

Commit b22b7cb

Browse files
author
Jonathan Rocher
committed
Added a Chaco example.
1 parent eea9bf4 commit b22b7cb

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

Chaco/zoom_overlay.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
"""
2+
The main executable file for the zoom_plot demo.
3+
Right-click and drag on the upper plot to select a region to view in detail
4+
in the lower plot. The selected region can be moved around by dragging,
5+
or resized by clicking on one of its edges and dragging.
6+
"""
7+
# Standard library imports
8+
import os
9+
# Major library imports
10+
from numpy import amin, amax, arange, searchsorted, sin, pi, linspace
11+
from enthought.enable.example_support import DemoFrame, demo_main
12+
# Enthought imports
13+
from enthought.enable.api import Component, ComponentEditor, Window
14+
from enthought.traits.api import HasTraits, Instance
15+
from enthought.traits.ui.api import Item, Group, View
16+
from enthought.util.resource import find_resource
17+
# Chaco imports
18+
from enthought.chaco.api import SimplePlotFrame, VPlotContainer
19+
from enthought.chaco.tools.api import RangeSelection
20+
# Relative imports
21+
from grid_plot_factory import create_gridded_line_plot
22+
from zoom_overlay import ZoomOverlay
23+
24+
sample_path = os.path.join('examples','data','sample.wav')
25+
alt_path = os.path.join('..','data','sample.wav')
26+
fname = find_resource('Chaco', sample_path, alt_path=alt_path,
27+
return_path=True)
28+
numpts = 3000
29+
def read_music_data():
30+
from wav_to_numeric import wav_to_numeric
31+
index, data = wav_to_numeric(fname)
32+
return index[:numpts], data[:numpts]
33+
def create_zoomed_plot():
34+
try:
35+
x,y = read_music_data()
36+
except:
37+
x = linspace(-10*pi, 10*pi, numpts)
38+
y = sin(x)
39+
main_plot = create_gridded_line_plot(x,y)
40+
zoom_plot = create_gridded_line_plot(x,y)
41+
outer_container = VPlotContainer(padding=30,
42+
fill_padding=True,
43+
spacing=50,
44+
stack_order='top_to_bottom',
45+
bgcolor='lightgray',
46+
use_backbuffer=True)
47+
outer_container.add(main_plot)
48+
outer_container.add(zoom_plot)
49+
50+
main_plot.controller = RangeSelection(main_plot)
51+
52+
zoom_overlay = ZoomOverlay(source=main_plot, destination=zoom_plot)
53+
outer_container.overlays.append(zoom_overlay)
54+
return outer_container
55+
#===============================================================================
56+
# Attributes to use for the plot view.
57+
size = (800, 600)
58+
title = fname
59+
60+
#===============================================================================
61+
# # Demo class that is used by the demo.py application.
62+
#===============================================================================
63+
class Demo(HasTraits):
64+
plot = Instance(Component)
65+
66+
traits_view = View(
67+
Group(
68+
Item('plot', editor=ComponentEditor(size=size),
69+
show_label=False),
70+
orientation = "vertical"),
71+
resizable=True, title=title,
72+
width=size[0], height=size[1]
73+
)
74+
75+
def _plot_default(self):
76+
return create_zoomed_plot()
77+
78+
demo = Demo()
79+
#===============================================================================
80+
# Stand-alone frame to display the plot.
81+
#===============================================================================
82+
class PlotFrame(DemoFrame):
83+
def _create_window(self):
84+
# Return a window containing our plots
85+
return Window(self, -1, component=create_zoomed_plot())
86+
87+
if __name__ == "__main__":
88+
demo_main(PlotFrame, size=size, title=title)
89+
#--EOF---

0 commit comments

Comments
 (0)