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.
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
13
- Pressing "p" will toggle the display of the image inspector overlay.
16
# Major library imports
17
from numpy import linspace, meshgrid, pi, sin
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
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, \
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)
41
# Create a plot data obect and give it this data
43
pd.set_data("imagedata", z)
47
img_plot = plot.img_plot("imagedata",
48
xbounds = xbounds[:2],
49
ybounds = ybounds[:2],
52
# Tweak some of the plot properties
53
plot.title = "My First Image Plot"
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)
65
img_plot.overlays.append(overlay)
68
#===============================================================================
69
# Attributes to use for the plot view.
71
title="Inspecting a Colormapped Image Plot"
73
#===============================================================================
74
# # Demo class that is used by the demo.py application.
75
#===============================================================================
76
class Demo(HasTraits):
77
plot = Instance(Component)
81
Item('plot', editor=ComponentEditor(size=size),
83
orientation = "vertical"),
84
resizable=True, title=title
87
def _plot_default(self):
88
return _create_plot_component()
92
if __name__ == "__main__":
93
demo.configure_traits()