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
# Enthought library imports
17
from enable.api import Component, ComponentEditor
18
from traits.api import HasTraits, Instance
19
from traitsui.api import Item, Group, View
22
from chaco.api import ArrayPlotData, HPlotContainer, Plot
23
from chaco.tools.api import PanTool, ZoomTool
25
#===============================================================================
26
# # Create the Chaco plot.
27
#===============================================================================
28
def _create_plot_component():
30
# Create some x-y data series to plot
31
x = linspace(-2.0, 10.0, 100)
32
pd = ArrayPlotData(index = x)
34
pd.set_data("y" + str(i), jn(i,x))
36
# Create some line plots of some of the data
37
plot1 = Plot(pd, title="Line Plot", padding=50, border_visible=True)
38
plot1.legend.visible = True
39
plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")
40
plot1.plot(("index", "y3"), name="j_3", color="blue")
42
# Attach some tools to the plot
43
plot1.tools.append(PanTool(plot1))
44
zoom = ZoomTool(component=plot1, tool_mode="box", always_on=False)
45
plot1.overlays.append(zoom)
47
# Create a second scatter plot of one of the datasets, linking its
48
# range to the first plot
49
plot2 = Plot(pd, range2d=plot1.range2d, title="Scatter plot", padding=50,
51
plot2.plot(('index', 'y3'), type="scatter", color="blue", marker="circle")
53
# Create a container and add our plots
54
container = HPlotContainer()
60
#===============================================================================
61
# Attributes to use for the plot view.
63
title="Basic x-y plots"
65
#===============================================================================
66
# # Demo class that is used by the demo.py application.
67
#===============================================================================
68
class Demo(HasTraits):
69
plot = Instance(Component)
73
Item('plot', editor=ComponentEditor(size=size),
75
orientation = "vertical"),
76
resizable=True, title=title
79
def _plot_default(self):
80
return _create_plot_component()
84
if __name__ == "__main__":
85
demo.configure_traits()