4
Displays a line plot, on which you can select an arbitrary range of x-values.
6
Left-drag will create a horizontal range selection;
7
this selection can then be dragged
8
around, or resized by dragging its edges.
11
# Major library imports
12
from numpy import arange
13
from scipy.special import jn
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
21
from chaco.api import create_line_plot, add_default_axes, add_default_grids
22
from chaco.tools.api import RangeSelection, RangeSelectionOverlay
26
#===============================================================================
27
# # Create the Chaco plot.
28
#===============================================================================
29
def _create_plot_component():
34
x = arange(low, high, (high-low)/numpoints)
36
# Plot a bessel function
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"
44
add_default_grids(plot)
45
add_default_axes(plot)
50
#===============================================================================
51
# Attributes to use for the plot view.
53
title="Simple line plot"
55
#===============================================================================
56
# # Demo class that is used by the demo.py application.
57
#===============================================================================
58
class Demo(HasTraits):
59
plot = Instance(Component)
63
Item('plot', editor=ComponentEditor(size=size),
65
orientation = "vertical"),
66
resizable=True, title=title,
67
width=size[0], height=size[1]
70
def _plot_default(self):
71
return _create_plot_component()
75
if __name__ == "__main__":
76
demo.configure_traits()