Changeset 47f695c9 in sasview for guitools/PlotPanel.py


Ignore:
Timestamp:
Apr 30, 2008 10: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

File:
1 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             
Note: See TracChangeset for help on using the changeset viewer.