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

« back to all changes in this revision

Viewing changes to examples/demo/multiaxis_using_Plot.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
 
Draws some x-y line and scatter plots. On the left hand plot:
4
 
 - Left-drag pans the plot.
5
 
 - Mousewheel up and down zooms the plot in and out.
6
 
 - Pressing "z" brings up the Zoom Box, and you can click-drag a rectangular
7
 
   region to zoom.  If you use a sequence of zoom boxes, pressing alt-left-arrow
8
 
   and alt-right-arrow moves you forwards and backwards through the "zoom
9
 
   history".
10
 
"""
11
 
 
12
 
# Major library imports
13
 
from numpy import linspace
14
 
from scipy.special import jn
15
 
 
16
 
from chaco.example_support import COLOR_PALETTE
17
 
# Enthought library imports
18
 
from enable.api import Component, ComponentEditor
19
 
from traits.api import HasTraits, Instance
20
 
from traitsui.api import Item, Group, View
21
 
 
22
 
# Chaco imports
23
 
from chaco.api import ArrayPlotData, Plot
24
 
from chaco.tools.api import BroadcasterTool, PanTool, ZoomTool
25
 
from chaco.api import create_line_plot, add_default_axes
26
 
 
27
 
#===============================================================================
28
 
# # Create the Chaco plot.
29
 
#===============================================================================
30
 
def _create_plot_component():
31
 
 
32
 
    # Create some x-y data series to plot
33
 
    x = linspace(-2.0, 10.0, 100)
34
 
    pd = ArrayPlotData(index = x)
35
 
    for i in range(5):
36
 
        pd.set_data("y" + str(i), jn(i,x))
37
 
 
38
 
    # Create some line plots of some of the data
39
 
    plot1 = Plot(pd)
40
 
    plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")
41
 
 
42
 
    # Tweak some of the plot properties
43
 
    plot1.title = "My First Line Plot"
44
 
    plot1.padding = 50
45
 
    plot1.padding_top = 75
46
 
    plot1.legend.visible = True
47
 
 
48
 
    x = linspace(-5, 15.0, 100)
49
 
    y = jn(5, x)
50
 
    foreign_plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[0]), width=2.0)
51
 
    left, bottom = add_default_axes(foreign_plot)
52
 
    left.orientation = "right"
53
 
    bottom.orientation = "top"
54
 
    plot1.add(foreign_plot)
55
 
 
56
 
    # Attach some tools to the plot
57
 
    broadcaster = BroadcasterTool()
58
 
    broadcaster.tools.append(PanTool(plot1))
59
 
    broadcaster.tools.append(PanTool(foreign_plot))
60
 
 
61
 
    for c in (plot1, foreign_plot):
62
 
        zoom = ZoomTool(component=c, tool_mode="box", always_on=False)
63
 
        broadcaster.tools.append(zoom)
64
 
 
65
 
    plot1.tools.append(broadcaster)
66
 
 
67
 
    return plot1
68
 
 
69
 
#===============================================================================
70
 
# Attributes to use for the plot view.
71
 
size=(900,500)
72
 
title="Multi-Y plot"
73
 
 
74
 
#===============================================================================
75
 
# # Demo class that is used by the demo.py application.
76
 
#===============================================================================
77
 
class Demo(HasTraits):
78
 
    plot = Instance(Component)
79
 
 
80
 
    traits_view = View(
81
 
                    Group(
82
 
                        Item('plot', editor=ComponentEditor(size=size),
83
 
                             show_label=False),
84
 
                        orientation = "vertical"),
85
 
                    resizable=True, title=title,
86
 
                    width=size[0], height=size[1]
87
 
                    )
88
 
 
89
 
    def _plot_default(self):
90
 
         return _create_plot_component()
91
 
 
92
 
demo = Demo()
93
 
 
94
 
if __name__ == "__main__":
95
 
    demo.configure_traits()
96
 
 
97
 
#--EOF---