2
from numpy import linspace, meshgrid, exp
4
from chaco.api import ArrayPlotData, Plot, jet
5
from enable.component_editor import ComponentEditor
6
from traits.api import Enum, HasTraits, Instance
7
from traitsui.api import Group, Item, View
9
class ImagePlotTraits(HasTraits):
12
origin = Enum("bottom left", "top left", "bottom right", "top right")
16
Item('origin', label="Data origin"),
17
Item('plot', editor=ComponentEditor(), show_label=False),
18
orientation = "vertical"),
19
width=600, height=600, resizable=True,
24
# Create the data and the PlotData object. For a 2D plot, we need to
25
# take the row of X points and Y points and create a grid from them
27
x = linspace(0, 8, 50)
28
y = linspace(0, 6, 50)
29
xgrid, ygrid = meshgrid(x, y)
30
z = exp(-(xgrid*xgrid + ygrid*ygrid) / 100)
31
plotdata = ArrayPlotData(imagedata = z)
32
# Create a Plot and associate it with the PlotData
34
# Create an image plot in the Plot
35
self.renderer = plot.img_plot("imagedata", name="plot1",
36
xbounds=xgrid, ybounds=ygrid, colormap=jet)[0]
39
def _origin_changed(self):
40
self.renderer.origin = self.origin
41
self.plot.request_redraw()
43
#===============================================================================
44
# demo object that is used by the demo.py application.
45
#===============================================================================
46
demo = ImagePlotTraits()
48
if __name__ == "__main__":
49
demo.configure_traits()