1
""" Demonstrates plots sharing datasources, ranges, etc. """
3
# Major library imports
4
from numpy import arange
5
from scipy.special import jn
7
# Enthought library imports
8
from enable.api import Component, ComponentEditor
9
from traits.api import HasTraits, Instance
10
from traitsui.api import Item, Group, View
13
from chaco.api import HPlotContainer, ArrayPlotData, Plot
14
from chaco.tools.api import LineInspector, ZoomTool, PanTool
16
#===============================================================================
17
# # Create the Chaco plot.
18
#===============================================================================
19
def _create_plot_component():
25
x = arange(low, high, (high-low)/numpoints)
26
plotdata = ArrayPlotData(x=x, y1=jn(0,x), y2=jn(1,x))
28
# Create the left plot
29
left_plot = Plot(plotdata)
30
left_plot.x_axis.title = "X"
31
left_plot.y_axis.title = "j0(x)"
32
renderer = left_plot.plot(("x", "y1"), type="line", color="blue",
34
renderer.overlays.append(LineInspector(renderer, axis='value',
37
renderer.overlays.append(LineInspector(renderer, axis="index",
40
left_plot.overlays.append(ZoomTool(left_plot, tool_mode="range"))
41
left_plot.tools.append(PanTool(left_plot))
43
# Create the right plot
44
right_plot = Plot(plotdata)
45
right_plot.index_range = left_plot.index_range
46
right_plot.orientation = "v"
47
right_plot.x_axis.title = "j1(x)"
48
right_plot.y_axis.title = "X"
49
renderer2 = right_plot.plot(("x","y2"), type="line", color="red", width=2.0)[0]
50
renderer2.index = renderer.index
51
renderer2.overlays.append(LineInspector(renderer2, write_metadata=True, is_listener=True))
52
renderer2.overlays.append(LineInspector(renderer2, axis="value", is_listener=True))
53
right_plot.overlays.append(ZoomTool(right_plot, tool_mode="range"))
54
right_plot.tools.append(PanTool(right_plot))
56
container = HPlotContainer(background="lightgray")
57
container.add(left_plot)
58
container.add(right_plot)
62
#===============================================================================
63
# Attributes to use for the plot view.
67
#===============================================================================
68
# # Demo class that is used by the demo.py application.
69
#===============================================================================
70
class Demo(HasTraits):
71
plot = Instance(Component)
75
Item('plot', editor=ComponentEditor(size=size),
77
orientation = "vertical"),
78
resizable=True, title=title,
79
width=size[0], height=size[1]
82
def _plot_default(self):
83
return _create_plot_component()
87
if __name__ == "__main__":
88
demo.configure_traits()