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

« back to all changes in this revision

Viewing changes to examples/demo/basic/cmap_image_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 colormapped image 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 exp, linspace, meshgrid
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
 
    # Create a scalar field to colormap
29
 
    xs = linspace(0, 10, 600)
30
 
    ys = linspace(0, 5, 600)
31
 
    x, y = meshgrid(xs,ys)
32
 
    z = exp(-(x**2+y**2)/100)
33
 
 
34
 
    # Create a plot data obect and give it this data
35
 
    pd = ArrayPlotData()
36
 
    pd.set_data("imagedata", z)
37
 
 
38
 
    # Create the plot
39
 
    plot = Plot(pd)
40
 
    img_plot = plot.img_plot("imagedata",
41
 
                             xbounds=(0, 10),
42
 
                             ybounds=(0, 5),
43
 
                             colormap=jet)[0]
44
 
 
45
 
    # Tweak some of the plot properties
46
 
    plot.title = "My First Image Plot"
47
 
    plot.padding = 50
48
 
 
49
 
    # Attach some tools to the plot
50
 
    plot.tools.append(PanTool(plot))
51
 
    zoom = ZoomTool(component=img_plot, tool_mode="box", always_on=False)
52
 
    img_plot.overlays.append(zoom)
53
 
    return plot
54
 
 
55
 
 
56
 
#===============================================================================
57
 
# Attributes to use for the plot view.
58
 
size=(800,600)
59
 
title="Basic Colormapped Image Plot"
60
 
 
61
 
#===============================================================================
62
 
# # Demo class that is used by the demo.py application.
63
 
#===============================================================================
64
 
class Demo(HasTraits):
65
 
    plot = Instance(Component)
66
 
 
67
 
    traits_view = View(
68
 
                    Group(
69
 
                        Item('plot', editor=ComponentEditor(size=size),
70
 
                             show_label=False),
71
 
                        orientation = "vertical"),
72
 
                    resizable=True, title=title
73
 
                    )
74
 
    def _plot_default(self):
75
 
         return _create_plot_component()
76
 
 
77
 
demo = Demo()
78
 
 
79
 
if __name__ == "__main__":
80
 
    demo.configure_traits()
81