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

« back to all changes in this revision

Viewing changes to examples/demo/basic/line_plot1.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
 
# Enthought library imports
17
 
from enable.api import Component, ComponentEditor
18
 
from traits.api import HasTraits, Instance
19
 
from traitsui.api import Item, Group, View
20
 
 
21
 
# Chaco imports
22
 
from chaco.api import ArrayPlotData, HPlotContainer, Plot
23
 
from chaco.tools.api import PanTool, ZoomTool
24
 
 
25
 
#===============================================================================
26
 
# # Create the Chaco plot.
27
 
#===============================================================================
28
 
def _create_plot_component():
29
 
 
30
 
    # Create some x-y data series to plot
31
 
    x = linspace(-2.0, 10.0, 100)
32
 
    pd = ArrayPlotData(index = x)
33
 
    for i in range(5):
34
 
        pd.set_data("y" + str(i), jn(i,x))
35
 
 
36
 
    # Create some line plots of some of the data
37
 
    plot1 = Plot(pd, title="Line Plot", padding=50, border_visible=True)
38
 
    plot1.legend.visible = True
39
 
    plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")
40
 
    plot1.plot(("index", "y3"), name="j_3", color="blue")
41
 
 
42
 
    # Attach some tools to the plot
43
 
    plot1.tools.append(PanTool(plot1))
44
 
    zoom = ZoomTool(component=plot1, tool_mode="box", always_on=False)
45
 
    plot1.overlays.append(zoom)
46
 
 
47
 
    # Create a second scatter plot of one of the datasets, linking its
48
 
    # range to the first plot
49
 
    plot2 = Plot(pd, range2d=plot1.range2d, title="Scatter plot", padding=50,
50
 
                 border_visible=True)
51
 
    plot2.plot(('index', 'y3'), type="scatter", color="blue", marker="circle")
52
 
 
53
 
    # Create a container and add our plots
54
 
    container = HPlotContainer()
55
 
    container.add(plot1)
56
 
    container.add(plot2)
57
 
 
58
 
    return container
59
 
 
60
 
#===============================================================================
61
 
# Attributes to use for the plot view.
62
 
size=(900,500)
63
 
title="Basic x-y plots"
64
 
 
65
 
#===============================================================================
66
 
# # Demo class that is used by the demo.py application.
67
 
#===============================================================================
68
 
class Demo(HasTraits):
69
 
    plot = Instance(Component)
70
 
 
71
 
    traits_view = View(
72
 
                    Group(
73
 
                        Item('plot', editor=ComponentEditor(size=size),
74
 
                             show_label=False),
75
 
                        orientation = "vertical"),
76
 
                    resizable=True, title=title
77
 
                    )
78
 
 
79
 
    def _plot_default(self):
80
 
         return _create_plot_component()
81
 
 
82
 
demo = Demo()
83
 
 
84
 
if __name__ == "__main__":
85
 
    demo.configure_traits()
86
 
 
87
 
#--EOF---