~ubuntu-branches/ubuntu/utopic/python-chaco/utopic

« back to all changes in this revision

Viewing changes to examples/demo/two_plots.py

  • Committer: Package Import Robot
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2014-06-01 17:04:08 UTC
  • mfrom: (7.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20140601170408-m86xvdjd83a4qon0
Tags: 4.4.1-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
 - Let the binary-predeb target work on the usr/lib/python* directory
   as we don't have usr/share/pyshared anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
""" Demonstrates plots sharing datasources, ranges, etc. """
2
 
 
3
 
# Major library imports
4
 
from numpy import arange
5
 
from scipy.special import jn
6
 
 
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
11
 
 
12
 
# Chaco imports
13
 
from chaco.api import HPlotContainer, ArrayPlotData, Plot
14
 
from chaco.tools.api import LineInspector, ZoomTool, PanTool
15
 
 
16
 
#===============================================================================
17
 
# # Create the Chaco plot.
18
 
#===============================================================================
19
 
def _create_plot_component():
20
 
 
21
 
    # Create the index
22
 
    numpoints = 100
23
 
    low = -5
24
 
    high = 15.0
25
 
    x = arange(low, high, (high-low)/numpoints)
26
 
    plotdata = ArrayPlotData(x=x, y1=jn(0,x), y2=jn(1,x))
27
 
 
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",
33
 
                              width=2.0)[0]
34
 
    renderer.overlays.append(LineInspector(renderer, axis='value',
35
 
                                            write_metadata=True,
36
 
                                            is_listener=True))
37
 
    renderer.overlays.append(LineInspector(renderer, axis="index",
38
 
                                            write_metadata=True,
39
 
                                            is_listener=True))
40
 
    left_plot.overlays.append(ZoomTool(left_plot, tool_mode="range"))
41
 
    left_plot.tools.append(PanTool(left_plot))
42
 
 
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))
55
 
 
56
 
    container = HPlotContainer(background="lightgray")
57
 
    container.add(left_plot)
58
 
    container.add(right_plot)
59
 
 
60
 
    return container
61
 
 
62
 
#===============================================================================
63
 
# Attributes to use for the plot view.
64
 
size=(750,500)
65
 
title="Two Plots"
66
 
 
67
 
#===============================================================================
68
 
# # Demo class that is used by the demo.py application.
69
 
#===============================================================================
70
 
class Demo(HasTraits):
71
 
    plot = Instance(Component)
72
 
 
73
 
    traits_view = View(
74
 
                    Group(
75
 
                        Item('plot', editor=ComponentEditor(size=size),
76
 
                             show_label=False),
77
 
                        orientation = "vertical"),
78
 
                    resizable=True, title=title,
79
 
                    width=size[0], height=size[1]
80
 
                    )
81
 
 
82
 
    def _plot_default(self):
83
 
         return _create_plot_component()
84
 
 
85
 
demo = Demo()
86
 
 
87
 
if __name__ == "__main__":
88
 
    demo.configure_traits()
89
 
 
90
 
# EOF