~ubuntu-branches/ubuntu/precise/python-chaco/precise

« back to all changes in this revision

Viewing changes to examples/multiaxis.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2008-12-29 02:34:05 UTC
  • Revision ID: james.westby@ubuntu.com-20081229023405-x7i4kp9mdxzmdnvu
Tags: upstream-3.0.1
ImportĀ upstreamĀ versionĀ 3.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
"""
 
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.
 
6
 
 
7
Left-drag pans the plot.
 
8
 
 
9
Right-click and dragging on the legend allows you to reposition the legend.
 
10
 
 
11
Double-clicking on line or scatter plots brings up a traits editor for the plot.
 
12
"""
 
13
 
 
14
# Major library imports
 
15
from numpy import arange, fabs, pi, sin
 
16
from scipy.special import jn
 
17
 
 
18
from enthought.chaco.example_support import COLOR_PALETTE
 
19
from enthought.enable.example_support import DemoFrame, demo_main
 
20
 
 
21
# Enthought library imports
 
22
from enthought.enable.api import Window
 
23
from enthought.traits.api import Dict, false, List
 
24
 
 
25
# Chaco imports
 
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
 
31
 
 
32
 
 
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
 
38
 
 
39
        # Create the initial X-series of data
 
40
        numpoints = 100
 
41
        low = -5
 
42
        high = 15.0
 
43
        x = arange(low, high+0.001, (high-low)/numpoints)
 
44
 
 
45
        # Plot some bessel functions
 
46
        plots = {}
 
47
        broadcaster = BroadcasterTool()
 
48
        for i in range(4):
 
49
            y = jn(i, x)
 
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
 
54
            if i == 0:
 
55
                plot0 = plot
 
56
                add_default_grids(plot)
 
57
                add_default_axes(plot)
 
58
 
 
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
 
61
            # the broadcaster.
 
62
            pan = PanTool(plot)
 
63
            #zoom = SimpleZoom(plot, tool_mode="box", always_on=False)
 
64
            broadcaster.tools.append(pan)
 
65
            #broadcaster.tools.append(zoom)
 
66
 
 
67
            container.add(plot)
 
68
            plots["Bessel j_%d"%i] = plot
 
69
 
 
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)
 
75
 
 
76
        # Add the broadcast tool to the container, instead of to an
 
77
        # individual plot
 
78
        container.tools.append(broadcaster)
 
79
 
 
80
        legend = Legend(component=container, padding=10, align="ur")
 
81
        legend.tools.append(LegendTool(legend, drag_button="right"))
 
82
        container.overlays.append(legend)
 
83
 
 
84
        # Set the list of plots on the legend
 
85
        legend.plots = plots
 
86
 
 
87
        # Add the title at the top
 
88
        container.overlays.append(PlotLabel("Bessel functions",
 
89
                                  component=container,
 
90
                                  font = "swiss 16",
 
91
                                  overlay_position="top"))
 
92
 
 
93
        # Add the traits inspector tool to the container
 
94
        container.tools.append(TraitsTool(container))
 
95
 
 
96
        return Window(self, -1, component=container)
 
97
 
 
98
if __name__ == "__main__":
 
99
    demo_main(PlotFrame, size=(800,700), title="Multi-Y plot")
 
100
 
 
101
# EOF