3
Displays multiple data sets with different scales in the same plot area,
4
and shows a separate, distinct, axis for each plot.
6
Interactions are the same as in multiaxis.py
9
# Major library imports
10
from numpy import linspace
11
from scipy.special import jn
13
from chaco.example_support import COLOR_PALETTE
14
# Enthought library imports
15
from enable.api import Component, ComponentEditor
16
from traits.api import HasTraits, Instance
17
from traitsui.api import Item, Group, View
20
from chaco.api import HPlotContainer, \
21
OverlayPlotContainer, PlotAxis, PlotGrid
22
from chaco.tools.api import BroadcasterTool, PanTool
23
from chaco.api import create_line_plot
25
#===============================================================================
26
# # Create the Chaco plot.
27
#===============================================================================
28
def _create_plot_component():
30
# Create some x-y data series to plot
31
plot_area = OverlayPlotContainer(border_visible=True)
32
container = HPlotContainer(padding=50, bgcolor="transparent")
33
#container.spacing = 15
35
x = linspace(-2.0, 10.0, 100)
37
color = tuple(COLOR_PALETTE[i])
39
renderer = create_line_plot((x, y), color=color)
40
plot_area.add(renderer)
41
#plot_area.padding_left = 20
43
axis = PlotAxis(orientation="left", resizable="v",
44
mapper = renderer.y_mapper,
45
axis_line_color=color,
47
tick_label_color=color,
49
bgcolor="transparent",
51
border_visible = True,)
53
axis.padding_left = 10
54
axis.padding_right = 10
59
# Use the last plot's X mapper to create an X axis and a
61
x_axis = PlotAxis(orientation="bottom", component=renderer,
62
mapper=renderer.x_mapper)
63
renderer.overlays.append(x_axis)
64
grid = PlotGrid(mapper=renderer.x_mapper, orientation="vertical",
65
line_color="lightgray", line_style="dot")
66
renderer.underlays.append(grid)
68
# Add the plot_area to the horizontal container
69
container.add(plot_area)
71
# Attach some tools to the plot
72
broadcaster = BroadcasterTool()
73
for plot in plot_area.components:
74
broadcaster.tools.append(PanTool(plot))
76
# Attach the broadcaster to one of the plots. The choice of which
77
# plot doesn't really matter, as long as one of them has a reference
78
# to the tool and will hand events to it.
79
plot.tools.append(broadcaster)
83
#===============================================================================
84
# Attributes to use for the plot view.
88
#===============================================================================
89
# # Demo class that is used by the demo.py application.
90
#===============================================================================
91
class Demo(HasTraits):
92
plot = Instance(Component)
96
Item('plot', editor=ComponentEditor(size=size),
98
orientation = "vertical"),
99
resizable=True, title=title,
100
width=size[0], height=size[1]
103
def _plot_default(self):
104
return _create_plot_component()
108
if __name__ == "__main__":
109
demo.configure_traits()