source: sasview/src/sas/sascalc/simulation/pointsmodelpy/tests/test2dui.py @ 7858575

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 7858575 was d85c194, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago

Remaining modules refactored

  • Property mode set to 100644
File size: 4.4 KB
RevLine 
[aa639ea]1#!/usr/bin/env python
2"""
3Demonstration of drawing a 2D image plot using the "hot" colormap
4"""
5
6#--------------------------------------------------------------------------------
7#  Imports:
8#--------------------------------------------------------------------------------
9
10import wx
11
12from enthought.traits import Any, Instance
13from enthought.enable.wx     import Window
14from enthought.pyface        import ApplicationWindow, GUI
15from enthought.util.numerix  import pi, concatenate, array, zeros, ones, \
16                                    arange, resize, ravel
17from enthought.util.numerix import Float as NumericFloat
18from math import sqrt, sin
19
20from enthought.chaco.plot_component import PlotComponent
21from enthought.chaco.plot_axis import PlotAxis
22from enthought.chaco.plot_canvas import PlotCanvas
23from enthought.chaco.plot_group import PlotGroup
24from enthought.chaco.image_plot_value import ImageData, CmapImagePlotValue
25from enthought.chaco.colormap import LinearColormap
26from enthought.chaco.colormap_legend import ColormapLegend
27from enthought.chaco.default_colormaps import hot, gray
28from enthought.chaco.demo.demo_base import PlotApplicationWindow
29
30
31class ImagePlotApplicationWindow( PlotApplicationWindow ):
32
33    ###########################################################################
34    # PlotApplicationWindow interface.
35    ###########################################################################
36   
37    def _create_plot( self ):
38        """ Create the plot to be displayed. """
39       
40        # Create the image data and the index values
41        #value_grid = zeros((100,100), NumericFloat)
42        from testlores2d import get2d_2       
43        value_grid = get2d_2()
44        #self._compute_function(value_grid)
45        index_vals = (arange(value_grid.shape[0]), arange(value_grid.shape[1]))
46
47        data = ImageData(value_grid, index_vals)
48        print value_grid, index_vals
49       
50        # Create the index axes
51        xaxis = PlotAxis(tick_visible=False, grid_visible=False)
52                        # bound_low = index_vals[0][0], bound_high = index_vals[0][-1])
53        yaxis = PlotAxis(tick_visible=False, grid_visible=False)
54                     #bound_low = index_vals[1][0], bound_high = index_vals[1][-1])
55        xaxis.visible = False
56        yaxis.visible = False
57       
58        # Create the value axis (i.e. colormap)
59        cmap = hot(0,1)
60               
61        # Create the Image PlotValue
62#        image = CmapImagePlotValue(data, cmap, axis_index = xaxis, axis = yaxis, type='image')
63        image = CmapImagePlotValue(data, cmap,type='image')
64        image.weight = 10
65       
66        cmap_legend = ColormapLegend(cmap, margin_width=31, margin_height=31)
67        cmap_legend.weight = 0.4
68       
69        group = PlotGroup(cmap_legend, image, orientation='horizontal')
70
71        return group
72
73    ###########################################################################
74    # Private interface.
75    ###########################################################################
76
77    def _compute_function(self, ary):
78        "Fills in ary with the sin(r)/r function"
79       
80        width, height = ary.shape
81        for i in range(width):
82            for j in range(height):
83                x = i - width / 2.0
84                x = x / (width/2.0) * 15
85                y = j - height / 2.0
86                y = y / (height/2.0) * 15
87               
88                radius = sqrt(x*x + y*y)
89                if radius == 0.0:
90                    ary[i,j] = 1
91                else:
92                    ary[i,j] = sin(radius) / radius
93
94        return
95   
96def main():
97
98    # Create the GUI (this does NOT start the GUI event loop).
99    gui = GUI()
100
101    # Screen size:
102    screen_width = gui.system_metrics.screen_width or 1024
103    screen_height = gui.system_metrics.screen_height or 768
104
105    # Create and open the main window.
106    window = ImagePlotApplicationWindow( title = "Plot" )
107    #window.plot_item = object
108    window.size = ( 2 * screen_width / 3, 2 * screen_height / 3 )
109    window.open()
110   
111    # Start the GUI event loop.
112    gui.start_event_loop()
113
114
115#===============================================================================
116#  Program start-up:
117#===============================================================================
118
119if __name__ == '__main__':
120    main()
Note: See TracBrowser for help on using the repository browser.