Changeset 47f695c9 in sasview for guitools


Ignore:
Timestamp:
Apr 30, 2008 8:52:41 AM (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:
eca05c8
Parents:
6ed101a
Message:

working

Location:
guitools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • guitools/PlotPanel.py

    r6ed101a r47f695c9  
    2323    if 'get_children' in dir(obj): 
    2424        for a in obj.get_children(): show_tree(a,d+1) 
    25  
     25def _rescale(lo,hi,step,pt=None,bal=None,scale='linear'): 
     26        """ 
     27        Rescale (lo,hi) by step, returning the new (lo,hi) 
     28        The scaling is centered on pt, with positive values of step 
     29        driving lo/hi away from pt and negative values pulling them in. 
     30        If bal is given instead of point, it is already in [0,1] coordinates. 
     31     
     32        This is a helper function for step-based zooming. 
     33        """ 
     34        # Convert values into the correct scale for a linear transformation 
     35        # TODO: use proper scale transformers 
     36        if scale=='log': 
     37            lo,hi = log10(lo),log10(hi) 
     38            if pt is not None: pt = log10(pt) 
     39     
     40        # Compute delta from axis range * %, or 1-% if persent is negative 
     41        if step > 0: 
     42            delta = float(hi-lo)*step/100 
     43        else: 
     44            delta = float(hi-lo)*step/(100-step) 
     45     
     46        # Add scale factor proportionally to the lo and hi values, preserving the 
     47        # point under the mouse 
     48        if bal is None: 
     49            bal = float(pt-lo)/(hi-lo) 
     50        lo = lo - bal*delta 
     51        hi = hi + (1-bal)*delta 
     52     
     53        # Convert transformed values back to the original scale 
     54        if scale=='log': 
     55            lo,hi = pow(10.,lo),pow(10.,hi) 
     56     
     57        return (lo,hi) 
    2658 
    2759 
     
    69101        self.prevYtrans =" " 
    70102        self.canvas.mpl_connect('scroll_event',self.onWheel) 
    71     def _rescale(lo,hi,step,pt=None,bal=None,scale='linear'): 
    72         """ 
    73         Rescale (lo,hi) by step, returning the new (lo,hi) 
    74         The scaling is centered on pt, with positive values of step 
    75         driving lo/hi away from pt and negative values pulling them in. 
    76         If bal is given instead of point, it is already in [0,1] coordinates. 
    77      
    78         This is a helper function for step-based zooming. 
    79         """ 
    80         # Convert values into the correct scale for a linear transformation 
    81         # TODO: use proper scale transformers 
    82         if scale=='log': 
    83             lo,hi = log10(lo),log10(hi) 
    84             if pt is not None: pt = log10(pt) 
    85      
    86         # Compute delta from axis range * %, or 1-% if persent is negative 
    87         if step > 0: 
    88             delta = float(hi-lo)*step/100 
    89         else: 
    90             delta = float(hi-lo)*step/(100-step) 
    91      
    92         # Add scale factor proportionally to the lo and hi values, preserving the 
    93         # point under the mouse 
    94         if bal is None: 
    95             bal = float(pt-lo)/(hi-lo) 
    96         lo = lo - bal*delta 
    97         hi = hi + (1-bal)*delta 
    98      
    99         # Convert transformed values back to the original scale 
    100         if scale=='log': 
    101             lo,hi = pow(10.,lo),pow(10.,hi) 
    102      
    103         return (lo,hi) 
     103        self.axes = [self.subplot] 
    104104 
    105105    def onWheel(self, event): 
     
    120120            ax.set_ylim((lo,hi)) 
    121121        else: 
    122             # Check if zoom happens in the axes 
     122             # Check if zoom happens in the axes 
    123123            xdata,ydata = None,None 
    124124            x,y = event.x,event.y 
     
    249249 
    250250   
    251           
    252     def onselect(self,event1, event2): 
    253         print"went here" 
    254         from matplotlib.widgets import RectangleSelector 
    255         from pylab import  show, gca, gcf 
    256  
    257         'event1 and event2 are the press and release events' 
    258         x1, y1 = event1.xdata, event1.ydata 
    259         x2, y2 = event2.xdata, event2.ydata 
    260         print "(%3.2f, %3.2f) --> (%3.2f, %3.2f)"%(x1,y1,x2,y2) 
    261         print " The button you used were: ",event1.button, event2.button 
    262         gca().set_xlim([x1,x2]) 
    263         gca().set_ylim([y1,y2]) 
    264         gcf().canvas.draw_idle() 
    265         
    266         # drawtype is 'box' or 'line' or 'none' 
    267         LS = RectangleSelector(self.subplot, onselect,drawtype='box',useblit=True) 
    268         show() 
    269  
    270  
    271  
     251   
    272252         
    273253    def onSaveImage(self, evt): 
     
    432412            if ( self.xscales=="x" ): 
    433413                item.returnTransformationx(transform.toX,transform.errToX) 
    434                  
    435414                self.set_xscale("linear") 
    436415                name, units = item.get_xaxis() 
     
    453432                self.set_yscale("linear") 
    454433                name, units = item.get_yaxis() 
    455                 item.check_data_PlottableY()  
    456434                self.graph.yaxis("log %s" % name,  "%s^{-1}" % units) 
    457435                 
     
    464442            if ( self.yscales=="log10(y)" ):  
    465443                item.returnTransformationy(transform.toX,transform.errToX) 
    466                 item.check_data_PlottableY()  
    467444                self.set_yscale("log")   
    468445                name, units = item.get_yaxis() 
     
    485462                self.set_yscale("linear") 
    486463                name, units = item.get_yaxis() 
    487                 item.check_data_PlottableY()  
    488464                self.graph.yaxis("%s" %name,  "%s" % units) 
    489465                 
     
    499475                self.set_yscale("linear") 
    500476                yname, yunits = item.get_yaxis() 
    501                 xname, xunits = item.get_xaxis() 
    502                 item.check_data_PlottableY()  
     477                xname, xunits = item.get_xaxis()  
    503478                self.graph.yaxis("Log %s%s^{2}" % (yname,xname),  "%s^{-1}%s^{-2}" % (yunits,xunits)) 
    504479             
  • guitools/plottables.py

    r6ed101a r47f695c9  
    383383        """ Reload view with new value to plot""" 
    384384        self.view = self.View(self.x, self.y, self.dx, self.dy) 
    385         #save the initial value 
    386         self.view.Xreel = self.view.x 
    387         self.view.Yreel = self.view.y 
    388         self.view.DXreel = self.view.dx 
    389         self.view.DYreel = self.view.dy 
    390         
    391      
     385         
    392386    def render(self,plot): 
    393387        """The base class makes sure the correct units are being used for 
     
    438432            self.dx = dx 
    439433            self.dy = dy 
    440             #to change x range to the reel range 
    441             self.Xreel = self.x 
    442             self.Yreel = self.y 
    443             self.DXreel = self.dx 
    444             self.DYreel = self.dy 
     434            
    445435            self.transx ="" 
    446436            self.transy ="" 
     
    459449            """ 
    460450             
    461              
    462451            # Sanity check 
    463452            if (x!=None) and (y!=None): 
     
    474463                self.dx = [] 
    475464                self.dy = [] 
    476                 tempx=[] 
    477                 tempdx=[] 
    478                 tempy=[] 
    479                 tempdy=[] 
     465                
    480466                if dx==None: 
    481467                    dx=numpy.zeros(len(x)) 
    482468                if dy==None: 
    483469                    dy=numpy.zeros(len(y)) 
    484                 
     470               
    485471                for i in range(len(x)): 
    486472                    try: 
     
    495481                         self.dy.append(tempdy) 
    496482                    except: 
    497                           
    498                          print "View.transform_x: skipping point %g" % x[i] 
    499                          print sys.exc_value    
     483                         print "View.transform: skipping point x %g" % x[i] 
     484                         print "View.transform: skipping point y %g" % y[i] 
     485                         print "View.transform: skipping point dy %g" % dy[i] 
     486                         print sys.exc_value   
     487                print len(self.x) 
     488                print len(self.dx) 
     489                print len(self.y) 
     490                print len(self.dy) 
    500491                # Sanity check 
    501492                if not (len(self.x)==len(self.dx))and(len(self.x)==len(self.dy))\ 
    502493                and(len(self.x)==len(self.y))and(len(self.y)==len(self.dy)) : 
    503494                        raise ValueError, "Plottable.View: Given x,y,dy and dx are not of the same length"  
    504              
     495                self.check_data_logX() 
     496                self.check_data_logY() 
     497                print len(self.x) 
     498                print len(self.dx) 
     499                print len(self.y) 
     500                print len(self.dy) 
    505501        def returntransformx(self,funcx,funcdx):     
    506502            self.funcx= funcx 
     
    515511         
    516512      
    517         def reelXrange(self): 
    518             self.x= self.Xreel 
    519             self.y= self.Yreel 
    520             self.dx= self.DXreel 
    521             self.dy= self.DYreel 
    522          
    523513        def check_data_logX(self):  
    524514            tempx=[] 
     
    540530                            tempdy.append(self.dy[i]) 
    541531                    except: 
    542                         #print "View.transform_x: skipping point %g" %self.x[i] 
     532                        print "check_data_logX: skipping point x %g" %self.x[i] 
    543533                        print sys.exc_value   
    544534                        pass  
    545535            
    546             self.x=[] 
    547             self.dx=[] 
    548             self.y=[] 
    549             self.dy=[] 
    550             self.x=tempx 
    551             self.y=tempy 
    552             self.dx=tempdx 
    553             self.dy=tempdy 
     536                self.x=[] 
     537                self.dx=[] 
     538                self.y=[] 
     539                self.dy=[] 
     540                self.x=tempx 
     541                self.y=tempy 
     542                self.dx=tempdx 
     543                self.dy=tempdy 
    554544             
    555545        def check_data_logY(self):  
     
    571561                            tempdy.append(self.dy[i]) 
    572562                     except: 
    573                         #print "View.transform_x: skipping point %g" %self.x[i] 
     563                        print "check_data_logY: skipping point %g" %self.y[i] 
    574564                        print sys.exc_value   
    575565                        pass 
    576566                 
    577             self.x=[] 
    578             self.dx=[] 
    579             self.y=[] 
    580             self.dy=[] 
    581             self.x=tempx 
    582             self.y=tempy 
    583             self.dx=tempdx 
    584             self.dy=tempdy 
     567                self.x=[] 
     568                self.dx=[] 
     569                self.y=[] 
     570                self.dy=[] 
     571                self.x=tempx 
     572                self.y=tempy 
     573                self.dx=tempdx 
     574                self.dy=tempdy 
    585575                 
    586576             
Note: See TracChangeset for help on using the changeset viewer.