~ubuntu-branches/ubuntu/utopic/python-chaco/utopic

« back to all changes in this revision

Viewing changes to examples/demo/range_selection_demo.py

  • Committer: Package Import Robot
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2014-06-01 17:04:08 UTC
  • mfrom: (7.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20140601170408-m86xvdjd83a4qon0
Tags: 4.4.1-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
 - Let the binary-predeb target work on the usr/lib/python* directory
   as we don't have usr/share/pyshared anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""
2
 
Range Selection tool
3
 
 
4
 
Displays a line plot, on which you can select an arbitrary range of x-values.
5
 
 
6
 
Left-drag will create a horizontal range selection; 
7
 
this selection can then be dragged
8
 
around, or resized by dragging its edges.
9
 
"""
10
 
 
11
 
# Major library imports
12
 
from numpy import arange
13
 
from scipy.special import jn
14
 
 
15
 
# Enthought library imports
16
 
from enable.api import Component, ComponentEditor
17
 
from traits.api import HasTraits, Instance
18
 
from traitsui.api import Item, Group, View
19
 
 
20
 
# Chaco imports
21
 
from chaco.api import create_line_plot, add_default_axes, add_default_grids
22
 
from chaco.tools.api import RangeSelection, RangeSelectionOverlay
23
 
 
24
 
 
25
 
 
26
 
#===============================================================================
27
 
# # Create the Chaco plot.
28
 
#===============================================================================
29
 
def _create_plot_component():
30
 
 
31
 
    numpoints = 100
32
 
    low = -5
33
 
    high = 15.001
34
 
    x = arange(low, high, (high-low)/numpoints)
35
 
 
36
 
    # Plot a bessel function
37
 
    y = jn(0, x)
38
 
    plot = create_line_plot((x,y), color=(0,0,1,1), width=2.0, index_sort="ascending")
39
 
    value_range = plot.value_mapper.range
40
 
    plot.active_tool = RangeSelection(plot, left_button_selects = True)
41
 
    plot.overlays.append(RangeSelectionOverlay(component=plot))
42
 
    plot.bgcolor = "white"
43
 
    plot.padding = 50
44
 
    add_default_grids(plot)
45
 
    add_default_axes(plot)
46
 
 
47
 
    return plot
48
 
 
49
 
 
50
 
#===============================================================================
51
 
# Attributes to use for the plot view.
52
 
size=(600,500)
53
 
title="Simple line plot"
54
 
 
55
 
#===============================================================================
56
 
# # Demo class that is used by the demo.py application.
57
 
#===============================================================================
58
 
class Demo(HasTraits):
59
 
    plot = Instance(Component)
60
 
 
61
 
    traits_view = View(
62
 
                    Group(
63
 
                        Item('plot', editor=ComponentEditor(size=size),
64
 
                             show_label=False),
65
 
                        orientation = "vertical"),
66
 
                    resizable=True, title=title,
67
 
                    width=size[0], height=size[1]
68
 
                    )
69
 
 
70
 
    def _plot_default(self):
71
 
         return _create_plot_component()
72
 
 
73
 
demo = Demo()
74
 
 
75
 
if __name__ == "__main__":
76
 
    demo.configure_traits()