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
12
# Major library imports
13
from numpy import linspace, meshgrid, pi
14
from scipy.special import jn
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
22
from chaco.api import ArrayPlotData, ColorBar, HPlotContainer, jet, \
24
from chaco.tools.api import PanTool, RangeSelection, \
25
RangeSelectionOverlay, ZoomTool
27
#===============================================================================
28
# # Create the Chaco plot.
29
#===============================================================================
30
def _create_plot_component():
31
# Create a scalar field to colormap# Create a scalar field to colormap
32
xbounds = (-2*pi, 2*pi, 600)
33
ybounds = (-1.5*pi, 1.5*pi, 300)
34
xs = linspace(*xbounds)
35
ys = linspace(*ybounds)
36
x, y = meshgrid(xs,ys)
39
# Create a plot data obect and give it this data
41
pd.set_data("imagedata", z)
45
plot.img_plot("imagedata",
51
# Tweak some of the plot properties
52
plot.title = "Selectable Image Plot"
55
# Right now, some of the tools are a little invasive, and we need the
56
# actual CMapImage object to give to them
57
my_plot = plot.plots["my_plot"][0]
59
# Attach some tools to the plot
60
plot.tools.append(PanTool(plot))
61
zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
62
plot.overlays.append(zoom)
64
# Create the colorbar, handing in the appropriate range and colormap
65
colormap = my_plot.color_mapper
66
colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
67
color_mapper=colormap,
73
colorbar.padding_top = plot.padding_top
74
colorbar.padding_bottom = plot.padding_bottom
76
# create a range selection for the colorbar
77
range_selection = RangeSelection(component=colorbar)
78
colorbar.tools.append(range_selection)
79
colorbar.overlays.append(RangeSelectionOverlay(component=colorbar,
82
fill_color="lightgray"))
84
# we also want to the range selection to inform the cmap plot of
85
# the selection, so set that up as well
86
range_selection.listeners.append(my_plot)
88
# Create a container to position the plot and the colorbar side-by-side
89
container = HPlotContainer(use_backbuffer = True)
91
container.add(colorbar)
92
container.bgcolor = "lightgray"
94
#my_plot.set_value_selection((-1.3, 6.9))
97
#===============================================================================
98
# Attributes to use for the plot view.
100
title="Colormapped Image Plot"
102
#===============================================================================
103
# # Demo class that is used by the demo.py application.
104
#===============================================================================
105
class Demo(HasTraits):
106
plot = Instance(Component)
110
Item('plot', editor=ComponentEditor(size=size),
112
orientation = "vertical"),
113
resizable=True, title=title
115
def _plot_default(self):
116
return _create_plot_component()
120
if __name__ == "__main__":
121
demo.configure_traits()