~ubuntu-branches/ubuntu/precise/python-chaco/precise

« back to all changes in this revision

Viewing changes to examples/tutorials/scipy2008/traits_image.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2008-12-29 02:34:05 UTC
  • Revision ID: james.westby@ubuntu.com-20081229023405-x7i4kp9mdxzmdnvu
Tags: upstream-3.0.1
ImportĀ upstreamĀ versionĀ 3.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
from numpy import linspace, meshgrid, exp
 
3
 
 
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
 
8
 
 
9
class ImagePlotTraits(HasTraits):
 
10
 
 
11
    plot = Instance(Plot)
 
12
    origin = Enum("bottom left", "top left", "bottom right", "top right")
 
13
 
 
14
    traits_view = View(
 
15
                    Group(
 
16
                        Item('origin', label="Data origin"),
 
17
                        Item('plot', editor=ComponentEditor(), show_label=False),
 
18
                        orientation = "vertical"),
 
19
                    width=600, height=600, resizable=True,
 
20
                    title="Chaco Plot"
 
21
                    )
 
22
 
 
23
    def __init__(self):
 
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
 
26
        # using meshgrid().
 
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
 
33
        plot = Plot(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]
 
36
        return plot
 
37
 
 
38
    def _origin_changed(self):
 
39
        self.renderer.origin = self.origin
 
40
        self.plot.request_redraw()
 
41
 
 
42
if __name__ == "__main__":
 
43
    ImagePlotTraits().configure_traits()
 
44