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

« back to all changes in this revision

Viewing changes to examples/demo/basic/image_inspector.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
 
Demonstrates the ImageInspectorTool and overlay on a colormapped image
4
 
plot.  The underlying plot is similar to the one in cmap_image_plot.py.
5
 
 
6
 
 - Left-drag pans the plot.
7
 
 - Mousewheel up and down zooms the plot in and out.
8
 
 - Pressing "z" brings up the Zoom Box, and you can click-drag a rectangular
9
 
   region to zoom.  If you use a sequence of zoom boxes, pressing alt-left-arrow
10
 
   and alt-right-arrow moves you forwards and backwards through the "zoom
11
 
   history".
12
 
 
13
 
 - Pressing "p" will toggle the display of the image inspector overlay.
14
 
"""
15
 
 
16
 
# Major library imports
17
 
from numpy import linspace, meshgrid, pi, sin
18
 
 
19
 
# Enthought library imports
20
 
from enable.api import Component, ComponentEditor
21
 
from traits.api import HasTraits, Instance
22
 
from traitsui.api import Item, Group, View
23
 
 
24
 
# Chaco imports
25
 
from chaco.api import ArrayPlotData, jet, Plot
26
 
from chaco.tools.api import PanTool, ZoomTool
27
 
from chaco.tools.image_inspector_tool import ImageInspectorTool, \
28
 
     ImageInspectorOverlay
29
 
 
30
 
#===============================================================================
31
 
# # Create the Chaco plot.
32
 
#===============================================================================
33
 
def _create_plot_component():# Create a scalar field to colormap
34
 
    xbounds = (-2*pi, 2*pi, 600)
35
 
    ybounds = (-1.5*pi, 1.5*pi, 300)
36
 
    xs = linspace(*xbounds)
37
 
    ys = linspace(*ybounds)
38
 
    x, y = meshgrid(xs,ys)
39
 
    z = sin(x)*y
40
 
 
41
 
    # Create a plot data obect and give it this data
42
 
    pd = ArrayPlotData()
43
 
    pd.set_data("imagedata", z)
44
 
 
45
 
    # Create the plot
46
 
    plot = Plot(pd)
47
 
    img_plot = plot.img_plot("imagedata",
48
 
                             xbounds = xbounds[:2],
49
 
                             ybounds = ybounds[:2],
50
 
                             colormap=jet)[0]
51
 
 
52
 
    # Tweak some of the plot properties
53
 
    plot.title = "My First Image Plot"
54
 
    plot.padding = 50
55
 
 
56
 
    # Attach some tools to the plot
57
 
    plot.tools.append(PanTool(plot))
58
 
    zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
59
 
    plot.overlays.append(zoom)
60
 
    imgtool = ImageInspectorTool(img_plot)
61
 
    img_plot.tools.append(imgtool)
62
 
    overlay = ImageInspectorOverlay(component=img_plot, image_inspector=imgtool,
63
 
                                    bgcolor="white", border_visible=True)
64
 
 
65
 
    img_plot.overlays.append(overlay)
66
 
    return plot
67
 
 
68
 
#===============================================================================
69
 
# Attributes to use for the plot view.
70
 
size = (800, 600)
71
 
title="Inspecting a Colormapped Image Plot"
72
 
 
73
 
#===============================================================================
74
 
# # Demo class that is used by the demo.py application.
75
 
#===============================================================================
76
 
class Demo(HasTraits):
77
 
    plot = Instance(Component)
78
 
 
79
 
    traits_view = View(
80
 
                    Group(
81
 
                        Item('plot', editor=ComponentEditor(size=size),
82
 
                             show_label=False),
83
 
                        orientation = "vertical"),
84
 
                    resizable=True, title=title
85
 
                    )
86
 
 
87
 
    def _plot_default(self):
88
 
         return _create_plot_component()
89
 
 
90
 
demo = Demo()
91
 
 
92
 
if __name__ == "__main__":
93
 
    demo.configure_traits()
94
 
 
95
 
#--EOF---