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
12
# Major library imports
13
from numpy import cosh, exp, linspace, meshgrid, pi, tanh
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
21
from chaco.api import ArrayPlotData, jet, Plot
22
from chaco.tools.api import PanTool, ZoomTool
24
#===============================================================================
25
# # Create the Chaco plot.
26
#===============================================================================
27
def _create_plot_component():
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)
36
# Create a plot data obect and give it this data
38
pd.set_data("imagedata", z)
40
# Create a contour polygon plot of the data
41
plot = Plot(pd, default_origin="top left")
42
plot.contour_plot("imagedata",
45
xbounds=(xs[0], xs[-1]),
46
ybounds=(ys[0], ys[-1]))
48
# Create a contour line plot for the data, too
49
plot.contour_plot("imagedata",
51
xbounds=(xs[0], xs[-1]),
52
ybounds=(ys[0], ys[-1]))
54
# Tweak some of the plot properties
55
plot.title = "My First Contour Plot"
57
plot.bg_color = "white"
58
plot.fill_padding = True
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)
66
#===============================================================================
67
# Attributes to use for the plot view.
69
title = "Basic Contour Plot"
71
#===============================================================================
72
# # Demo class that is used by the demo.py application.
73
#===============================================================================
74
class Demo(HasTraits):
75
plot = Instance(Component)
79
Item('plot', editor=ComponentEditor(size=size),
81
orientation = "vertical"),
82
resizable=True, title=title
85
def _plot_default(self):
86
return _create_plot_component()
90
if __name__ == "__main__":
91
demo.configure_traits()