~ubuntu-branches/ubuntu/utopic/python-chaco/utopic

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2014-06-01 17:04:08 UTC
  • mfrom: (7.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20140601170408-m86xvdjd83a4qon0
Tags: 4.4.1-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
 - Let the binary-predeb target work on the usr/lib/python* directory
   as we don't have usr/share/pyshared anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
from numpy import linspace, meshgrid, exp
3
 
 
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
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 an image plot in the Plot
35
 
        self.renderer = plot.img_plot("imagedata", name="plot1",
36
 
                                      xbounds=xgrid, ybounds=ygrid, colormap=jet)[0]
37
 
        self.plot = plot
38
 
 
39
 
    def _origin_changed(self):
40
 
        self.renderer.origin = self.origin
41
 
        self.plot.request_redraw()
42
 
 
43
 
#===============================================================================
44
 
# demo object that is used by the demo.py application.
45
 
#===============================================================================
46
 
demo = ImagePlotTraits()
47
 
 
48
 
if __name__ == "__main__":
49
 
    demo.configure_traits()
50