Changeset 55d89f8 in sasview for src/sas/qtgui/Plotter2D.py


Ignore:
Timestamp:
Dec 6, 2016 6:35:10 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
64f1e93
Parents:
6d05e1d
Message:

Context menu 3D plotting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Plotter2D.py

    r6d05e1d r55d89f8  
    1111 
    1212class Plotter2D(PlotterBase): 
    13     def __init__(self, parent=None, quickplot=False): 
     13    def __init__(self, parent=None, quickplot=False, dimension=2): 
     14        self.dimension = dimension 
    1415        super(Plotter2D, self).__init__(parent, quickplot=quickplot) 
    1516 
     
    3132        self.zmax=data.zmax 
    3233        self.label=data.name 
    33         self.dimension=2 
    3434        self.xLabel="%s(%s)"%(data._xaxis, data._xunit) 
    3535        self.yLabel="%s(%s)"%(data._yaxis, data._yunit) 
     
    4141        """ 
    4242        # create an axis object 
    43         ax = self.ax 
     43        zmin_2D_temp = self.zmin 
     44        zmax_2D_temp = self.zmax 
     45        if self.scale == 'log_{10}': 
     46            self.scale = 'linear' 
     47            if not self.zmin is None: 
     48                zmin_2D_temp = numpy.pow(10, self.zmin) 
     49            if not self.zmax is None: 
     50                zmax_2D_temp = numpy.pow(10, self.zmax) 
     51        else: 
     52            self.scale = 'log_{10}' 
     53            if not self.zmin is None: 
     54                # min log value: no log(negative) 
     55                if self.zmin <= 0: 
     56                    zmin_2D_temp = -32 
     57                else: 
     58                    zmin_2D_temp = numpy.log10(self.zmin) 
     59            if not self.zmax is None: 
     60                zmax_2D_temp = numpy.log10(self.zmax) 
    4461 
    45         # graph properties 
    46         ax.set_xlabel(self.x_label) 
    47         ax.set_ylabel(self.y_label) 
    48         # Title only for regular charts 
    49         if not self.quickplot: 
    50             ax.set_title(label=self._title) 
    51  
    52         # Re-adjust colorbar 
    53         self.figure.subplots_adjust(left=0.2, right=.8, bottom=.2) 
    54  
    55         output = PlotUtilities.build_matrix(self._data.data, self.qx_data, self.qy_data) 
    56  
    57         im = ax.imshow(output, 
    58                        interpolation='nearest', 
    59                        origin='lower', 
    60                        vmin=self.zmin, vmax=self.zmax, 
    61                        cmap=self.cmap, 
    62                        extent=(self.xmin, self.xmax, 
    63                                self.ymin, self.ymax)) 
    64  
    65         cbax = self.figure.add_axes([0.84, 0.2, 0.02, 0.7]) 
    66         cb = self.figure.colorbar(im, cax=cbax) 
    67         cb.update_bruteforce(im) 
    68         cb.set_label('$' + self.scale + '$') 
    69  
    70         # Schedule the draw for the next time the event loop is idle. 
    71         self.canvas.draw_idle() 
     62        self.image(data=self.data.data, qx_data=self.qx_data, 
     63                   qy_data=self.qy_data, xmin=self.xmin, 
     64                   xmax=self.xmax, 
     65                   ymin=self.ymin, ymax=self.ymax, 
     66                   cmap=self.cmap, zmin=zmin_2D_temp, 
     67                   zmax=zmax_2D_temp) 
    7268 
    7369    def contextMenuQuickPlot(self): 
     
    8177        self.actionCopyToClipboard = self.contextMenu.addAction("Copy to Clipboard") 
    8278        self.contextMenu.addSeparator() 
    83         self.actionToggleGrid = self.contextMenu.addAction("Toggle Grid On/Off") 
    84         self.contextMenu.addSeparator() 
     79        if self.dimension == 2: 
     80            self.actionToggleGrid = self.contextMenu.addAction("Toggle Grid On/Off") 
     81            self.contextMenu.addSeparator() 
    8582        self.actionChangeScale = self.contextMenu.addAction("Toggle Linear/Log Scale") 
    8683 
     
    8986        self.actionPrintImage.triggered.connect(self.onImagePrint) 
    9087        self.actionCopyToClipboard.triggered.connect(self.onClipboardCopy) 
    91         self.actionToggleGrid.triggered.connect(self.onGridToggle) 
     88        if self.dimension == 2: 
     89            self.actionToggleGrid.triggered.connect(self.onGridToggle) 
    9290        self.actionChangeScale.triggered.connect(self.onToggleScale) 
    9391 
     
    9593        """ 
    9694        Toggle axis and replot image 
    97  
    9895        """ 
    99         zmin_2D_temp = self.zmin 
    100         zmax_2D_temp = self.zmax 
    101         if self.scale == 'log_{10}': 
    102             self.scale = 'linear' 
    103             if not self.zmin is None: 
    104                 zmin_2D_temp = math.pow(10, self.zmin) 
    105             if not self.zmax is None: 
    106                 zmax_2D_temp = math.pow(10, self.zmax) 
    107         else: 
    108             self.scale = 'log_{10}' 
    109             if not self.zmin is None: 
    110                 # min log value: no log(negative) 
    111                 if self.zmin <= 0: 
    112                     zmin_2D_temp = -32 
    113                 else: 
    114                     zmin_2D_temp = math.log10(self.zmin) 
    115             if not self.zmax is None: 
    116                 zmax_2D_temp = math.log10(self.zmax) 
    117  
    118         self.image(data=self.data.data, qx_data=self.qx_data, 
    119                    qy_data=self.qy_data, xmin=self.xmin, 
    120                    xmax=self.xmax, 
    121                    ymin=self.ymin, ymax=self.ymax, 
    122                    cmap=self.cmap, zmin=zmin_2D_temp, 
    123                    zmax=zmax_2D_temp) 
    124  
     96        self.plot() 
    12597 
    12698    def image(self, data, qx_data, qy_data, xmin, xmax, ymin, ymax, 
     
    129101        """ 
    130102        Render the current data 
    131  
    132103        """ 
    133         #self.data = data 
    134104        self.qx_data = qx_data 
    135105        self.qy_data = qy_data 
     
    140110        self.zmin = zmin 
    141111        self.zmax = zmax 
    142         #c = self.color(color) 
    143112        # If we don't have any data, skip. 
    144113        if data == None: 
    145114            return 
    146115        if data.ndim == 1: 
    147             #output = self._build_matrix() 
    148116            output = PlotUtilities.build_matrix(data, self.qx_data, self.qy_data) 
    149117        else: 
     
    157125                    zmin_temp = self.zmin_2D 
    158126                    output[output > 0] = numpy.log10(output[output > 0]) 
    159                     #In log scale Negative values are not correct in general 
    160                     #output[output<=0] = math.log(numpy.min(output[output>0])) 
    161127                elif self.zmin <= 0: 
    162128                    zmin_temp = self.zmin 
     
    166132                    zmin_temp = self.zmin 
    167133                    output[output > 0] = numpy.log10(output[output > 0]) 
    168                     #In log scale Negative values are not correct in general 
    169                     #output[output<=0] = math.log(numpy.min(output[output>0])) 
    170134            except: 
    171135                #Too many problems in 2D plot with scale 
     
    193157            self.figure.subplots_adjust(left=0.1, right=.8, bottom=.1) 
    194158 
    195             X = self.x_bins[0:-1] 
    196             Y = self.y_bins[0:-1] 
     159            X = self._data.x_bins[0:-1] 
     160            Y = self._data.y_bins[0:-1] 
    197161            X, Y = numpy.meshgrid(X, Y) 
    198162 
     
    200164                # mpl >= 1.0.0 
    201165                ax = self.figure.gca(projection='3d') 
    202                 #ax.disable_mouse_rotation() 
    203166                cbax = self.figure.add_axes([0.84, 0.1, 0.02, 0.8]) 
    204167                if len(X) > 60: 
     
    218181            im = ax.plot_surface(X, Y, output, rstride=1, cstride=1, cmap=cmap, 
    219182                                 linewidth=0, antialiased=False) 
    220             self.set_axis_off() 
     183            self.ax.set_axis_off() 
    221184 
    222185        if cbax == None: 
Note: See TracChangeset for help on using the changeset viewer.