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

« back to all changes in this revision

Viewing changes to examples/demo/stacked_axis.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
 
#!/usr/bin/env python
2
 
"""
3
 
Displays multiple data sets with different scales in the same plot area,
4
 
and shows a separate, distinct, axis for each plot.
5
 
 
6
 
Interactions are the same as in multiaxis.py
7
 
"""
8
 
 
9
 
# Major library imports
10
 
from numpy import linspace
11
 
from scipy.special import jn
12
 
 
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
18
 
 
19
 
# Chaco imports
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
24
 
 
25
 
#===============================================================================
26
 
# # Create the Chaco plot.
27
 
#===============================================================================
28
 
def _create_plot_component():
29
 
 
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
34
 
 
35
 
    x = linspace(-2.0, 10.0, 100)
36
 
    for i in range(5):
37
 
        color = tuple(COLOR_PALETTE[i])
38
 
        y = jn(i, x)
39
 
        renderer = create_line_plot((x, y), color=color)
40
 
        plot_area.add(renderer)
41
 
        #plot_area.padding_left = 20
42
 
 
43
 
        axis = PlotAxis(orientation="left", resizable="v",
44
 
                    mapper = renderer.y_mapper,
45
 
                    axis_line_color=color,
46
 
                    tick_color=color,
47
 
                    tick_label_color=color,
48
 
                    title_color=color,
49
 
                    bgcolor="transparent",
50
 
                    title = "jn_%d" % i,
51
 
                    border_visible = True,)
52
 
        axis.bounds = [60,0]
53
 
        axis.padding_left = 10
54
 
        axis.padding_right = 10
55
 
 
56
 
        container.add(axis)
57
 
 
58
 
        if i == 4:
59
 
            # Use the last plot's X mapper to create an X axis and a
60
 
            # vertical grid
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)
67
 
 
68
 
    # Add the plot_area to the horizontal container
69
 
    container.add(plot_area)
70
 
 
71
 
    # Attach some tools to the plot
72
 
    broadcaster = BroadcasterTool()
73
 
    for plot in plot_area.components:
74
 
        broadcaster.tools.append(PanTool(plot))
75
 
 
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)
80
 
 
81
 
    return container
82
 
 
83
 
#===============================================================================
84
 
# Attributes to use for the plot view.
85
 
size=(900,500)
86
 
title="Multi-Y plot"
87
 
 
88
 
#===============================================================================
89
 
# # Demo class that is used by the demo.py application.
90
 
#===============================================================================
91
 
class Demo(HasTraits):
92
 
    plot = Instance(Component)
93
 
 
94
 
    traits_view = View(
95
 
                    Group(
96
 
                        Item('plot', editor=ComponentEditor(size=size),
97
 
                             show_label=False),
98
 
                        orientation = "vertical"),
99
 
                    resizable=True, title=title,
100
 
                    width=size[0], height=size[1]
101
 
                    )
102
 
 
103
 
    def _plot_default(self):
104
 
        return _create_plot_component()
105
 
 
106
 
demo = Demo()
107
 
 
108
 
if __name__ == "__main__":
109
 
    demo.configure_traits()
110
 
 
111
 
#--EOF---
112