2
from numpy import linspace, meshgrid, exp
4
from enthought.chaco.api import ArrayPlotData, Plot, jet
5
from enthought.enable.component_editor import ComponentEditor
6
from enthought.traits.api import Enum, HasTraits, Instance
7
from enthought.traits.ui.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 a line plot in the Plot
35
self.renderer = plot.img_plot("imagedata", name="plot1", xbounds=x, ybounds=y, colormap=jet)[0]
38
def _origin_changed(self):
39
self.renderer.origin = self.origin
40
self.plot.request_redraw()
42
if __name__ == "__main__":
43
ImagePlotTraits().configure_traits()