3
Draws several overlapping line plots like simple_line.py, but uses a separate
4
Y range for each plot. Also has a second Y-axis on the right hand side.
5
Demonstrates use of the BroadcasterTool.
7
Left-drag pans the plot.
9
Right-click and dragging on the legend allows you to reposition the legend.
11
Double-clicking on line or scatter plots brings up a traits editor for the plot.
14
# Major library imports
15
from numpy import arange, fabs, pi, sin
16
from scipy.special import jn
18
from enthought.chaco.example_support import COLOR_PALETTE
19
from enthought.enable.example_support import DemoFrame, demo_main
21
# Enthought library imports
22
from enthought.enable.api import Window
23
from enthought.traits.api import Dict, false, List
26
from enthought.chaco.api import create_line_plot, add_default_axes, add_default_grids, \
27
OverlayPlotContainer, PlotLabel, VPlotContainer, \
28
create_scatter_plot, Legend, PlotComponent, PlotAxis
29
from enthought.chaco.tools.api import PanTool, RectZoomTool, SimpleZoom, \
30
LegendTool, TraitsTool, BroadcasterTool
33
class PlotFrame(DemoFrame):
34
def _create_window(self):
35
container = OverlayPlotContainer(padding = 50, fill_padding = True,
36
bgcolor = "lightgray", use_backbuffer=True)
37
self.container = container
39
# Create the initial X-series of data
43
x = arange(low, high+0.001, (high-low)/numpoints)
45
# Plot some bessel functions
47
broadcaster = BroadcasterTool()
50
plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[i]), width=2.0)
51
plot.index.sort_order = "ascending"
52
plot.bgcolor = "white"
53
plot.border_visible = True
56
add_default_grids(plot)
57
add_default_axes(plot)
59
# Create a pan tool and give it a reference to the plot it should
60
# manipulate, but don't attach it to the plot. Instead, attach it to
63
#zoom = SimpleZoom(plot, tool_mode="box", always_on=False)
64
broadcaster.tools.append(pan)
65
#broadcaster.tools.append(zoom)
68
plots["Bessel j_%d"%i] = plot
70
# Add an axis on the right-hand side that corresponds to the second plot.
71
# Note that it uses plot.value_mapper instead of plot0.value_mapper.
72
plot1 = plots["Bessel j_1"]
73
axis = PlotAxis(plot1, orientation="right")
74
plot1.underlays.append(axis)
76
# Add the broadcast tool to the container, instead of to an
78
container.tools.append(broadcaster)
80
legend = Legend(component=container, padding=10, align="ur")
81
legend.tools.append(LegendTool(legend, drag_button="right"))
82
container.overlays.append(legend)
84
# Set the list of plots on the legend
87
# Add the title at the top
88
container.overlays.append(PlotLabel("Bessel functions",
91
overlay_position="top"))
93
# Add the traits inspector tool to the container
94
container.tools.append(TraitsTool(container))
96
return Window(self, -1, component=container)
98
if __name__ == "__main__":
99
demo_main(PlotFrame, size=(800,700), title="Multi-Y plot")