3
A modification of line_plot1.py that shows the second plot as a subwindow
4
of the first. You can pan and zoom the second plot just like the first,
5
and you can move it around my right-click and dragging in the smaller plot.
8
# Major library imports
9
from numpy import linspace
10
from scipy.special import jn
12
# Enthought library imports
13
from enable.api import Component, ComponentEditor
14
from traits.api import HasTraits, Instance
15
from traitsui.api import Item, Group, View
18
from chaco.api import ArrayPlotData, OverlayPlotContainer, Plot
19
from chaco.tools.api import PanTool, ZoomTool, MoveTool
21
#===============================================================================
22
# # Create the Chaco plot.
23
#===============================================================================
24
def _create_plot_component():
25
# Create some x-y data series to plot
26
x = linspace(-2.0, 10.0, 100)
27
pd = ArrayPlotData(index = x)
29
pd.set_data("y" + str(i), jn(i,x))
31
# Create some line plots of some of the data
33
plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")
34
plot1.plot(("index", "y3"), name="j_3", color="blue")
36
# Tweak some of the plot properties
37
plot1.title = "Inset Plot"
40
# Attach some tools to the plot
41
plot1.tools.append(PanTool(plot1))
42
zoom = ZoomTool(component=plot1, tool_mode="box", always_on=False)
43
plot1.overlays.append(zoom)
45
# Create a second scatter plot of one of the datasets, linking its
46
# range to the first plot
47
plot2 = Plot(pd, range2d=plot1.range2d, padding=50)
48
plot2.plot(('index', 'y3'), type="scatter", color="blue", marker="circle")
49
plot2.set(resizable = "",
53
border_visible = True,
56
plot2.tools.append(PanTool(plot2))
57
plot2.tools.append(MoveTool(plot2, drag_button="right"))
58
zoom = ZoomTool(component=plot2, tool_mode="box", always_on=False)
59
plot2.overlays.append(zoom)
61
# Create a container and add our plots
62
container = OverlayPlotContainer()
67
#===============================================================================
68
# Attributes to use for the plot view.
72
#===============================================================================
73
# # Demo class that is used by the demo.py application.
74
#===============================================================================
75
class Demo(HasTraits):
76
plot = Instance(Component)
80
Item('plot', editor=ComponentEditor(size=size),
82
orientation = "vertical"),
83
resizable=True, title=title
86
def _plot_default(self):
87
return _create_plot_component()
91
if __name__ == "__main__":
92
demo.configure_traits()