Changeset b6972a0f in sasview


Ignore:
Timestamp:
May 29, 2008 12:41:04 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:
ab6098f
Parents:
05da1f89
Message:

some improvement in the way to display units

File:
1 edited

Legend:

Unmodified
Added
Removed
  • guitools/PlotPanel.py

    r05da1f89 rb6972a0f  
    2020from plottables import Graph 
    2121#(FuncFitEvent, EVT_FUNC_FIT) = wx.lib.newevent.NewEvent() 
    22 import math,pylab 
     22import math,pylab,re 
     23 
    2324def show_tree(obj,d=0): 
    2425    """Handy function for displaying a tree of graph objects""" 
     
    2627    if 'get_children' in dir(obj): 
    2728        for a in obj.get_children(): show_tree(a,d+1) 
     29         
     30def convertUnit(pow,unit): 
     31    """  
     32        Displays the unit with the proper convertion 
     33        @param pow: the user set the power of the unit 
     34        @param unit: the unit of the data 
     35    """  
     36    toks=re.match("^", unit) 
     37    if not toks==None: 
     38        unitValue= re.split("{",unit) 
     39        unitPower= re.split("}",unitValue[1]) 
     40        power= int(unitPower[0])*pow 
     41        word= unitValue[0]+"{"+str(power)+"}" 
     42        if power==1: 
     43            tempUnit=re.split("\^",unitValue[0]) 
     44            unit=tempUnit[0] 
     45        else: 
     46            unit = word 
     47    #print"this is unit",unit 
     48    return unit 
    2849def _rescale(lo,hi,step,pt=None,bal=None,scale='linear'): 
    2950        """ 
     
    487508                self.set_xscale("linear") 
    488509                name, units = item.get_xaxis() 
    489                 self.graph.xaxis("%s" % name,  "%s^{-1}" % units) 
     510                self.graph.xaxis("%s" % name,  "%s" % units) 
     511                 
    490512                 
    491513            if ( self.xLabel=="x^(2)" ): 
     
    493515                self.set_xscale('linear') 
    494516                name, units = item.get_xaxis() 
    495                 self.graph.xaxis("%s^{2}" % name,  "%s^{-2}" % units) 
     517                units=convertUnit(2,units)  
     518                self.graph.xaxis("%s^{2}" % name,  "%s" % units) 
     519                 
    496520                 
    497521            if (self.xLabel=="log10(x)" ): 
     
    499523                self.set_xscale("log") 
    500524                name, units = item.get_xaxis()  
    501                 self.graph.xaxis("\log_{10}\ \  (%s)" % name,  "%s^{-1}" % units) 
     525                self.graph.xaxis("\log_{10}\ \  (%s)" % name,  "%s" % units) 
     526                 
    502527                 
    503528            if ( self.yLabel=="ln(y)" ): 
     
    505530                self.set_yscale("linear") 
    506531                name, units = item.get_yaxis() 
    507                 self.graph.yaxis("log\ \ %s" % name,  "%s^{-1}" % units) 
     532                self.graph.yaxis("log\ \ %s" % name,  "%s" % units) 
     533                 
    508534                 
    509535            if ( self.yLabel=="y" ): 
     
    511537                self.set_yscale("linear") 
    512538                name, units = item.get_yaxis() 
    513                 self.graph.yaxis("%s" % name,  "%s^{-1}" % units) 
     539                self.graph.yaxis("%s" % name,  "%s" % units) 
     540                
    514541                 
    515542            if ( self.yLabel=="log10(y)" ):  
     
    517544                self.set_yscale("log")   
    518545                name, units = item.get_yaxis() 
    519                 self.graph.yaxis("\log_{10}\ \ (%s)" % name,  "%s^{-1}" % units) 
     546                self.graph.yaxis("\log_{10}\ \ (%s)" % name,  "%s" % units) 
     547                 
    520548                 
    521549            if ( self.yLabel=="y^(2)" ): 
     
    523551                self.set_yscale("linear") 
    524552                name, units = item.get_yaxis() 
    525                 self.graph.yaxis("%s^{2}" % name,  "%s^{-2}" % units) 
     553                units=convertUnit(2,units)  
     554                self.graph.yaxis("%s^{2}" % name,  "%s" % units) 
     555                 
    526556                 
    527557            if ( self.yLabel =="1/y"): 
     
    529559                self.set_yscale("linear") 
    530560                name, units = item.get_yaxis() 
    531                 self.graph.yaxis("1/%s" % name,  "\ \%s" % units) 
     561                units=convertUnit(-1,units) 
     562                self.graph.yaxis("1/%s" % name,  "%s" % units) 
    532563                 
    533564            if ( self.yLabel =="1/sqrt(y)" ): 
     
    535566                self.set_yscale("linear") 
    536567                name, units = item.get_yaxis() 
     568                units=convertUnit(-1,units) 
    537569                self.graph.yaxis("1/\sqrt{%s}" %name,  "%s" % units) 
    538570                 
     
    542574                yname, yunits = item.get_yaxis() 
    543575                xname, xunits = item.get_xaxis() 
    544                 self.graph.yaxis("log\ (%s \ \ %s)" % (yname,xname),  "%s^{-1}%s^{-1}" % (yunits,xunits)) 
     576                self.graph.yaxis("log\ (%s \ \ %s)" % (yname,xname),  "%s%s" % (yunits,xunits)) 
     577                
    545578                 
    546579            if ( self.yLabel =="ln(y*x^(2))"): 
     
    549582                yname, yunits = item.get_yaxis() 
    550583                xname, xunits = item.get_xaxis()  
    551                 self.graph.yaxis("Log (%s \ \ %s^{2})" % (yname,xname),  "%s^{-1}%s^{-2}" % (yunits,xunits)) 
     584                xunits = convertUnit(2,xunits)  
     585                self.graph.yaxis("Log (%s \ \ %s)" % (yname,xname),  "%s%s" % (yunits,xunits)) 
     586                 
    552587             
    553588            if ( self.yLabel =="ln(y*x^(4))"): 
     
    556591                yname, yunits = item.get_yaxis() 
    557592                xname, xunits = item.get_xaxis() 
    558                 self.graph.yaxis("Log (%s \ \ %s^{4})" % (yname,xname),  "%s^{-1}%s^{-4}" % (yunits,xunits)) 
    559              
     593                xunits = convertUnit(4,xunits)  
     594                self.graph.yaxis("Log (%s \ \ %s)" % (yname,xname),  "%s%s" % (yunits,xunits)) 
     595                 
    560596            if ( self.viewModel == "Guinier lny vs x^(2)"): 
    561597                 
     
    563599                self.set_xscale('linear') 
    564600                name, units = item.get_xaxis() 
    565                 self.graph.xaxis("%s^{2}" % name,  "%s^{-2}" % units) 
     601                units = convertUnit(2,units)  
     602                self.graph.xaxis("%s^{2}" % name,  "%s" % units) 
     603                 
    566604                 
    567605                item.transformY(transform.toLogX,transform.errToLogX ) 
    568606                self.set_yscale("linear") 
    569607                name, units = item.get_yaxis() 
    570                 self.graph.yaxis("$Log %s$" % name,  "%s^{-1}" % units) 
     608                self.graph.yaxis("$Log %s$" % name,  "%s" % units) 
     609                
    571610                 
    572611            item.transformView() 
    573612             
    574         #item.name = self.yLabel+" vs " +self.xLabel  
     613         
    575614        self.resetFitView()    
    576615        self.prevXtrans = self.xLabel  
     
    579618        self.subplot.figure.canvas.draw_idle() 
    580619         
     620         
     621     
    581622    def onFitDisplay(self, tempx,tempy,xminView,xmaxView,xmin,xmax,func): 
    582623        """ 
Note: See TracChangeset for help on using the changeset viewer.