3
Draws some x-y line and scatter plots. On the left hand plot:
4
- Left-drag pans the plot.
5
- Mousewheel up and down zooms the plot in and out.
6
- Pressing "z" brings up the Zoom Box, and you can click-drag a rectangular
7
region to zoom. If you use a sequence of zoom boxes, pressing alt-left-arrow
8
and alt-right-arrow moves you forwards and backwards through the "zoom
12
# Major library imports
13
from numpy import linspace
14
from scipy.special import jn
16
from chaco.example_support import COLOR_PALETTE
17
# Enthought library imports
18
from enable.api import Component, ComponentEditor
19
from traits.api import HasTraits, Instance
20
from traitsui.api import Item, Group, View
23
from chaco.api import ArrayPlotData, Plot
24
from chaco.tools.api import BroadcasterTool, PanTool, ZoomTool
25
from chaco.api import create_line_plot, add_default_axes
27
#===============================================================================
28
# # Create the Chaco plot.
29
#===============================================================================
30
def _create_plot_component():
32
# Create some x-y data series to plot
33
x = linspace(-2.0, 10.0, 100)
34
pd = ArrayPlotData(index = x)
36
pd.set_data("y" + str(i), jn(i,x))
38
# Create some line plots of some of the data
40
plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")
42
# Tweak some of the plot properties
43
plot1.title = "My First Line Plot"
45
plot1.padding_top = 75
46
plot1.legend.visible = True
48
x = linspace(-5, 15.0, 100)
50
foreign_plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[0]), width=2.0)
51
left, bottom = add_default_axes(foreign_plot)
52
left.orientation = "right"
53
bottom.orientation = "top"
54
plot1.add(foreign_plot)
56
# Attach some tools to the plot
57
broadcaster = BroadcasterTool()
58
broadcaster.tools.append(PanTool(plot1))
59
broadcaster.tools.append(PanTool(foreign_plot))
61
for c in (plot1, foreign_plot):
62
zoom = ZoomTool(component=c, tool_mode="box", always_on=False)
63
broadcaster.tools.append(zoom)
65
plot1.tools.append(broadcaster)
69
#===============================================================================
70
# Attributes to use for the plot view.
74
#===============================================================================
75
# # Demo class that is used by the demo.py application.
76
#===============================================================================
77
class Demo(HasTraits):
78
plot = Instance(Component)
82
Item('plot', editor=ComponentEditor(size=size),
84
orientation = "vertical"),
85
resizable=True, title=title,
86
width=size[0], height=size[1]
89
def _plot_default(self):
90
return _create_plot_component()
94
if __name__ == "__main__":
95
demo.configure_traits()