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

« back to all changes in this revision

Viewing changes to examples/demo/basic/contour_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 a contour polygon plot with a contour line plot on top
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 cosh, exp, linspace, meshgrid, pi, tanh
14
 
 
15
 
# Enthought library imports
16
 
from enable.api import Component, ComponentEditor
17
 
from traits.api import HasTraits, Instance
18
 
from traitsui.api import Item, Group, View
19
 
 
20
 
# Chaco imports
21
 
from chaco.api import ArrayPlotData, jet, Plot
22
 
from chaco.tools.api import PanTool, ZoomTool
23
 
 
24
 
#===============================================================================
25
 
# # Create the Chaco plot.
26
 
#===============================================================================
27
 
def _create_plot_component():
28
 
 
29
 
    # Create a scalar field to contour
30
 
    xs = linspace(-2*pi, 2*pi, 600)
31
 
    ys = linspace(-1.5*pi, 1.5*pi, 300)
32
 
    x, y = meshgrid(xs,ys)
33
 
    z = tanh(x*y/6)*cosh(exp(-y**2)*x/3)
34
 
    z = x*y
35
 
 
36
 
    # Create a plot data obect and give it this data
37
 
    pd = ArrayPlotData()
38
 
    pd.set_data("imagedata", z)
39
 
 
40
 
    # Create a contour polygon plot of the data
41
 
    plot = Plot(pd, default_origin="top left")
42
 
    plot.contour_plot("imagedata",
43
 
                      type="poly",
44
 
                      poly_cmap=jet,
45
 
                      xbounds=(xs[0], xs[-1]),
46
 
                      ybounds=(ys[0], ys[-1]))
47
 
 
48
 
    # Create a contour line plot for the data, too
49
 
    plot.contour_plot("imagedata",
50
 
                      type="line",
51
 
                      xbounds=(xs[0], xs[-1]),
52
 
                      ybounds=(ys[0], ys[-1]))
53
 
 
54
 
    # Tweak some of the plot properties
55
 
    plot.title = "My First Contour Plot"
56
 
    plot.padding = 50
57
 
    plot.bg_color = "white"
58
 
    plot.fill_padding = True
59
 
 
60
 
    # Attach some tools to the plot
61
 
    plot.tools.append(PanTool(plot))
62
 
    zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
63
 
    plot.overlays.append(zoom)
64
 
    return plot
65
 
 
66
 
#===============================================================================
67
 
# Attributes to use for the plot view.
68
 
size = (800, 600)
69
 
title = "Basic Contour Plot"
70
 
 
71
 
#===============================================================================
72
 
# # Demo class that is used by the demo.py application.
73
 
#===============================================================================
74
 
class Demo(HasTraits):
75
 
    plot = Instance(Component)
76
 
 
77
 
    traits_view = View(
78
 
                    Group(
79
 
                        Item('plot', editor=ComponentEditor(size=size),
80
 
                             show_label=False),
81
 
                        orientation = "vertical"),
82
 
                    resizable=True, title=title
83
 
                    )
84
 
 
85
 
    def _plot_default(self):
86
 
         return _create_plot_component()
87
 
 
88
 
demo = Demo()
89
 
 
90
 
if __name__ == "__main__":
91
 
    demo.configure_traits()
92
 
 
93
 
#--EOF---