Changeset b43a009 in sasview for guitools/plottables.py


Ignore:
Timestamp:
May 5, 2008 2:44:40 PM (16 years ago)
Author:
Gervaise Alina <gervyh@…>
Branches:
master, 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, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
edce46e
Parents:
2d06beb
Message:

some modificatiosn made

File:
1 edited

Legend:

Unmodified
Added
Removed
  • guitools/plottables.py

    r150c04a rb43a009  
    5353            if not cond: return False 
    5454        return True 
    55 def error_msg(msg, parent=None): 
    56     """ 
    57     Signal an error condition -- in a GUI, popup a error dialog 
    58     """ 
    59     # Code brought with minor podifications from mpl.backends.backend_wx 
    60     # Copyright (C) Jeremy O'Donoghue & John Hunter, 2003-4 
    61     dialog =wx.MessageDialog(parent  = parent, 
    62                              message = msg, 
    63                              caption = 'Polplot error', 
    64                              style=wx.OK | wx.CENTRE) 
    65     dialog.ShowModal() 
    66     dialog.Destroy() 
    67     return None 
     55 
    6856# Graph structure for holding multiple plottables 
    6957class Graph: 
     
    204192                     "title":""} 
    205193        self.plottables = {} 
    206     def setGraph(self,listofplottable): 
    207         self.plottables = listofplottable 
     194         
     195         
    208196    def _make_labels(self): 
    209197        # Find groups of related plottables 
     
    223211     
    224212    def returnPlottable(self): 
     213        """ 
     214            This method returns a dictionary of plottables contained in graph 
     215            It is just by Plotpanel to interact with the complete list of plottables  
     216            inside the graph. 
     217        """ 
    225218        return self.plottables 
    226219 
     
    234227        plot.render() 
    235228    
    236     def clear(self,plot):  
    237         plot.clear() 
     229    
    238230 
    239231    def __init__(self,**kw): 
     
    376368    ##Use the following if @classmethod doesn't work 
    377369    # labels = classmethod(labels) 
    378     def getTransform(self,transx,transy): 
    379         self.view.transx = transx 
    380         self.view.transy = transy 
     370    def setLabel(self,labelx,labely): 
     371        """ 
     372            It takes a label of the x and y transformation and set View parameters 
     373            @param transx: The label of x transformation is sent by Properties Dialog 
     374            @param transy: The label of y transformation is sent Properties Dialog 
     375        """ 
     376        self.view.xLabel= labelx 
     377        self.view.yLabel = labely 
    381378         
    382379    def __init__(self): 
     
    418415     
    419416    def transformView(self): 
    420         
     417        """ 
     418            It transforms x, y before displaying 
     419        """ 
    421420        self.view.transform( self.x, self.y, self.dx,self.dy) 
    422421         
    423422    def returnValuesOfView(self): 
     423        """ 
     424            Return View parameters and it is used by Fit Dialog 
     425        """ 
    424426        return self.view.returnXview() 
    425427     
    426428    def check_data_PlottableX(self):  
     429        """ 
     430            Since no transformation is made for log10(x), check that  
     431            no negative values is plot in log scale 
     432        """ 
    427433        self.view.check_data_logX() 
    428434         
    429435    def check_data_PlottableY(self):  
     436        """ 
     437            Since no transformation is made for log10(y), check that  
     438            no negative values is plot in log scale 
     439        """ 
    430440        self.view.check_data_logY()  
    431441         
    432     def returnTransformationx(self,transx,transdx): 
    433         self.view.returntransformx(transx,transdx) 
    434          
    435     def returnTransformationy(self,transy,transdy): 
    436         self.view.returntransformy(transy,transdy) 
     442    def transformX(self,transx,transdx): 
     443        """ 
     444            Receive pointers to function that transform x and dx  
     445            and set corresponding View pointers 
     446            @param transx: pointer to function that transforms x 
     447            @param transdx: pointer to function that transforms dx 
     448        """ 
     449        self.view.setTransformX(transx,transdx) 
     450         
     451    def transformY(self,transy,transdy): 
     452        """ 
     453            Receive pointers to function that transform y and dy  
     454            and set corresponding View pointers 
     455            @param transy: pointer to function that transforms y 
     456            @param transdy: pointer to function that transforms dy 
     457        """ 
     458        self.view.setTransformY(transy,transdy) 
     459         
    437460    def onReset(self): 
     461        """ 
     462            Reset x, y, dx, dy view with its parameters 
     463        """ 
    438464        self.view.onResetView() 
     465         
    439466    def onFitRange(self,xmin=None,xmax=None): 
     467        """ 
     468            It limits View data range to plot from min to max 
     469            @param xmin: the minimum value of x to plot. 
     470            @param xmax: the maximum value of x to plot 
     471        """ 
    440472        self.view.onFitRangeView(xmin,xmax) 
     473         
    441474    class View: 
    442475        """ 
     
    454487            self.dx = dx 
    455488            self.dy = dy 
    456             #to change x range to the reel range 
     489            # To change x range to the reel range 
    457490            self.Xreel = self.x 
    458491            self.Yreel = self.y 
    459492            self.DXreel = self.dx 
    460493            self.DYreel = self.dy 
    461              
    462             self.transx ="" 
    463             self.transy ="" 
    464             # function to transform x and y 
     494            # Labels of x and y received from Properties Dialog 
     495            self.xLabel ="" 
     496            self.yLabel ="" 
     497            # Function to transform x, y, dx and dy 
    465498            self.funcx= None 
    466499            self.funcy= None 
     
    469502        def transform(self, x=None,y=None,dx=None, dy=None): 
    470503            """ 
    471                 Transforms the x and dx vectors and stores the output. 
    472                  
    473                 @param func: function to apply to the data 
     504                Transforms the x,y,dx and dy vectors and stores the output in View parameters 
     505         
    474506                @param x: array of x values 
    475                 @param dx: array of error values 
    476                 @param errfunc: function to apply to errors 
     507                @param y: array of y values 
     508                @param dx: array of  errors values on x  
     509                @param dy: array of error values on y 
    477510            """ 
    478511             
    479512            # Sanity check 
    480             if (x!=None) and (y!=None): 
     513            # Do the transofrmation only when x and y are empty 
     514            if (x!=None) and (y!=None):  
    481515                if dx and not len(x)==len(dx): 
    482516                        raise ValueError, "Plottable.View: Given x and dx are not of the same length"  
     
    522556                and(len(self.x)==len(self.y))and(len(self.y)==len(self.dy)) : 
    523557                        raise ValueError, "Plottable.View: Given x,y,dy and dx are not of the same length"  
     558                # Check that negative values are not plot on x and y axis for log10 transformation 
    524559                self.check_data_logX() 
    525560                self.check_data_logY() 
     561                # Store x ,y dx,and dy in their full range for reset 
    526562                self.Xreel = self.x 
    527563                self.Yreel = self.y 
    528564                self.DXreel = self.dx 
    529565                self.DYreel = self.dy 
     566                 
     567                 
     568                 
    530569        def onResetView(self): 
    531             self.x=self.Xreel 
    532             self.y=self.Yreel 
    533             self.dx=self.DXreel 
    534             self.dy=self.DYreel 
    535         def returntransformx(self,funcx,funcdx):     
     570            """ 
     571                Reset x,y,dx and y in their full range  and in the initial scale 
     572                in case their previous range has changed   
     573            """ 
     574            self.x = self.Xreel 
     575            self.y = self.Yreel 
     576            self.dx = self.DXreel 
     577            self.dy = self.DYreel 
     578             
     579        def setTransformX(self,funcx,funcdx):   
     580            """ 
     581                Receive pointers to function that transform x and dx  
     582                and set corresponding View pointers 
     583                @param transx: pointer to function that transforms x 
     584                @param transdx: pointer to function that transforms dx 
     585            """ 
    536586            self.funcx= funcx 
    537587            self.funcdx= funcdx 
    538588             
    539         def returntransformy(self,funcy,funcdy):     
     589        def setTransformY(self,funcy,funcdy): 
     590            """ 
     591                Receive pointers to function that transform y and dy  
     592                and set corresponding View pointers 
     593                @param transx: pointer to function that transforms y 
     594                @param transdx: pointer to function that transforms dy 
     595            """     
    540596            self.funcy= funcy 
    541597            self.funcdy= funcdy 
    542598        
    543599        def returnXview(self): 
     600            """ 
     601                Return View  x,y,dx,dy 
     602            """ 
    544603            return self.x,self.y,self.dx,self.dy 
    545604         
    546605      
    547606        def check_data_logX(self):  
     607            """ 
     608                 Remove negative value in x vector  
     609                 to avoid plotting negative value of Log10 
     610            """ 
    548611            tempx=[] 
    549612            tempdx=[] 
     
    554617            if self.dy==None: 
    555618                self.dy=numpy.zeros(len(self.y)) 
    556             if self.transx=="log10(x)" : 
     619            if self.xLabel=="log10(x)" : 
    557620                for i in range(len(self.x)): 
    558621                    try: 
     
    568631                        pass  
    569632            
    570                 self.x=[] 
    571                 self.dx=[] 
    572                 self.y=[] 
    573                 self.dy=[] 
    574                 self.x=tempx 
    575                 self.y=tempy 
    576                 self.dx=tempdx 
    577                 self.dy=tempdy 
     633                self.x = tempx 
     634                self.y = tempy 
     635                self.dx = tempdx 
     636                self.dy = tempdy 
    578637             
    579638        def check_data_logY(self):  
     639            """ 
     640                 Remove negative value in y vector  
     641                 to avoid plotting negative value of Log10 
     642            """ 
    580643            tempx=[] 
    581644            tempdx=[] 
     
    586649            if self.dy==None: 
    587650                self.dy=numpy.zeros(len(self.y)) 
    588             if (self.transy == "log10(y)" ): 
     651            if (self.yLabel == "log10(y)" ): 
    589652                for i in range(len(self.x)): 
    590653                     try: 
     
    598661                        print sys.exc_value   
    599662                        pass 
    600                  
    601                 self.x=[] 
    602                 self.dx=[] 
    603                 self.y=[] 
    604                 self.dy=[] 
    605                 self.x=tempx 
    606                 self.y=tempy 
    607                 self.dx=tempdx 
    608                 self.dy=tempdy 
     663               
     664                self.x = tempx 
     665                self.y = tempy 
     666                self.dx = tempdx 
     667                self.dy = tempdy 
    609668                 
    610669        def onFitRangeView(self,xmin=None,xmax=None): 
     670            """ 
     671                It limits View data range to plot from min to max 
     672                @param xmin: the minimum value of x to plot. 
     673                @param xmax: the maximum value of x to plot 
     674            """ 
    611675            tempx=[] 
    612676            tempdx=[] 
     
    676740        The title is the name that will show up on the legend. 
    677741        """ 
    678         self.name= "theo" 
     742        self.name= "theory" 
    679743        self.x = x 
    680744        self.y = y 
     
    683747        self.yaxis( 'intensity', 'cm') 
    684748        self.view = self.View(self.x, self.y, None, self.dy) 
     749         
    685750    def render(self,plot,**kw): 
    686751        #plot.curve(self.x,self.y,dy=self.dy,**kw) 
Note: See TracChangeset for help on using the changeset viewer.