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

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.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since a1b8fee was a1b8fee, checked in by andyfaff, 7 years ago

MAINT: from future import print_function

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