Changeset 3477478 in sasview for src/sas/plottools/plottables.py


Ignore:
Timestamp:
Mar 5, 2015 12:38:29 PM (9 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
b9dbd6b
Parents:
2df0b74
Message:

pylint fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/plottools/plottables.py

    r79492222 r3477478  
    4545import numpy 
    4646import sys 
    47  
     47import logging 
    4848 
    4949if 'any' not in dir(__builtins__): 
     
    5353                return True 
    5454        return False 
    55      
     55 
    5656    def all(L): 
    5757        for cond in L: 
     
    6161 
    6262 
    63 class Graph: 
     63class Graph(object): 
    6464    """ 
    6565    Generic plottables graph structure. 
    66      
     66 
    6767    Plot styles are based on color/symbol lists.  The user gets to select 
    6868    the list of colors/symbols/sizes to choose from, not the application 
     
    7777    the plottable objects themselves will need to provide the transformations. 
    7878    Here are some examples from reflectometry: :: 
    79      
     79 
    8080       independent: x -> f(x) 
    8181          monitor scaling: y -> M*y 
     
    9191          spin asymmetry: x -> x1, y -> (y1 - y2)/(y1 + y2) 
    9292          vector net: x -> x1, y -> y1*cos(y2*pi/180) 
    93            
     93 
    9494    Multiple transformations are possible, such as Q4 spin asymmetry 
    9595 
     
    122122    Graphs need to be printable.  A page layout program for entire plots 
    123123    would be nice. 
    124      
     124 
    125125    """ 
    126126    def _xaxis_transformed(self, name, units): 
     
    134134        self.prop["xlabel"] = name 
    135135        self.prop["xunit"] = units 
    136          
     136 
    137137    def _yaxis_transformed(self, name, units): 
    138138        """ 
     
    145145        self.prop["ylabel"] = name 
    146146        self.prop["yunit"] = units 
    147          
     147 
    148148    def xaxis(self, name, units): 
    149149        """ 
     
    167167        self.prop["ylabel_base"] = name 
    168168        self.prop["yunit_base"] = units 
    169          
     169 
    170170    def title(self, name): 
    171171        """ 
     
    173173        """ 
    174174        self.prop["title"] = name 
    175          
     175 
    176176    def get(self, key): 
    177177        """ 
     
    216216        """Detect if any graphed plottables have changed""" 
    217217        return any([p.changed() for p in self.plottables]) 
    218      
     218 
    219219    def get_range(self): 
    220220        """ 
    221221        Return the range of all displayed plottables 
    222222        """ 
    223         min = None 
    224         max = None 
     223        min_value = None 
     224        max_value = None 
    225225        for p in self.plottables: 
    226226            if p.hidden == True: 
     
    228228            if not p.x == None: 
    229229                for x_i in p.x: 
    230                     if min == None or x_i < min: 
    231                         min = x_i 
    232                     if max == None or x_i > max: 
    233                         max = x_i 
    234         return min, max 
    235      
     230                    if min_value == None or x_i < min_value: 
     231                        min_value = x_i 
     232                    if max_value == None or x_i > max_value: 
     233                        max_value = x_i 
     234        return min_value, max_value 
     235 
    236236    def replace(self, plottable): 
    237237        """Replace an existing plottable from the graph""" 
     
    252252            del self.plottables[plottable] 
    253253            self.color = len(self.plottables) 
    254              
     254 
    255255    def reset_scale(self): 
    256256        """ 
     
    268268                     "title": ""} 
    269269        self.plottables = {} 
    270      
     270 
    271271    def _make_labels(self): 
    272272        """ 
     
    284284            labels.update(c.labels(sets[c])) 
    285285        return labels 
    286      
     286 
    287287    def get_plottable(self, name): 
    288288        """ 
     
    294294                return item 
    295295        return None 
    296      
     296 
    297297    def returnPlottable(self): 
    298298        """ 
     
    302302        """ 
    303303        return self.plottables 
    304      
    305     def render(self,plot): 
     304 
     305    def render(self, plot): 
    306306        """Redraw the graph""" 
    307307        plot.connect.clearall() 
     
    312312            if p.custom_color is not None: 
    313313                p.render(plot, color=p.custom_color, symbol=0, 
    314                 markersize=p.markersize, label=labels[p]) 
     314                         markersize=p.markersize, label=labels[p]) 
    315315            else: 
    316316                p.render(plot, color=self.plottables[p], symbol=0, 
    317                      markersize=p.markersize, label=labels[p]) 
     317                         markersize=p.markersize, label=labels[p]) 
    318318        plot.render() 
    319     
     319 
    320320    def __init__(self, **kw): 
    321321        self.reset() 
     
    328328# No need to inherit from this class, just need to provide 
    329329# the same methods. 
    330 class Transform: 
     330class Transform(object): 
    331331    """ 
    332332    Define a transform plugin to the plottable architecture. 
    333      
     333 
    334334    Transforms operate on axes.  The plottable defines the 
    335335    set of transforms available for it, and the axes on which 
    336336    they operate.  These transforms can operate on the x axis 
    337337    only, the y axis only or on the x and y axes together. 
    338      
     338 
    339339    This infrastructure is not able to support transformations 
    340340    such as log and polar plots as these require full control 
    341341    over the drawing of axes and grids. 
    342      
     342 
    343343    A transform has a number of attributes. 
    344      
     344 
    345345    name 
    346346      user visible name for the transform.  This will 
    347347      appear in the context menu for the axis and the transform 
    348348      menu for the graph. 
    349          
     349 
    350350    type 
    351351      operational axis.  This determines whether the 
     
    353353      menus, or if it should appear in the context menu for 
    354354      the graph. 
    355          
     355 
    356356    inventory 
    357       (not implemented)  
     357      (not implemented) 
    358358      a dictionary of user settable parameter names and 
    359359      their associated types.  These should appear as keyword 
    360360      arguments to the transform call.  For example, Fresnel 
    361361      reflectivity requires the substrate density: 
    362       ``{ 'rho': type.Value(10e-6/units.angstrom**2) }``        
     362      ``{ 'rho': type.Value(10e-6/units.angstrom**2) }`` 
    363363      Supply reasonable defaults in the callback so that 
    364364      limited plotting clients work even though they cannot 
    365365      set the inventory. 
    366          
     366 
    367367    """ 
    368368    def __call__(self, plottable, **kwargs): 
     
    375375        plottable should store the underlying data but set 
    376376        the standard x,dx,y,dy,z,dz attributes appropriately. 
    377          
     377 
    378378        If the call raises a NotImplemented error the dataline 
    379379        will not be plotted.  The associated string will usually 
     
    381381        The application may or may not display the message to the 
    382382        user, along with an indication of which plottable was at fault. 
    383          
     383 
    384384        """ 
    385385        raise NotImplemented, "Not a valid transform" 
     
    428428    name = None 
    429429    # Data 
    430     x  = None 
    431     y  = None 
     430    x = None 
     431    y = None 
    432432    dx = None 
    433433    dy = None 
     
    438438    custom_color = None 
    439439    markersize = 5  # default marker size is 'size 5' 
    440      
     440 
    441441    def __init__(self): 
    442442        self.view = View() 
     
    445445        self._yaxis = "" 
    446446        self._yunit = "" 
    447          
     447 
    448448    def __setattr__(self, name, value): 
    449449        """ 
     
    454454        if name in ['x', 'y', 'dx', 'dy']: 
    455455            self.reset_view() 
    456             #print "self.%s has been called" % name 
     456            # print "self.%s has been called" % name 
    457457 
    458458    def set_data(self, x, y, dx=None, dy=None): 
     
    464464        self.dx = dx 
    465465        self.transformView() 
    466      
     466 
    467467    def xaxis(self, name, units): 
    468468        """ 
    469469        Set the name and unit of x_axis 
    470          
     470 
    471471        :param name: the name of x-axis 
    472472        :param units: the units of x_axis 
    473          
     473 
    474474        """ 
    475475        self._xaxis = name 
     
    479479        """ 
    480480        Set the name and unit of y_axis 
    481          
     481 
    482482        :param name: the name of y-axis 
    483483        :param units: the units of y_axis 
    484          
     484 
    485485        """ 
    486486        self._yaxis = name 
    487487        self._yunit = units 
    488          
     488 
    489489    def get_xaxis(self): 
    490490        """Return the units and name of x-axis""" 
    491491        return self._xaxis, self._xunit 
    492      
     492 
    493493    def get_yaxis(self): 
    494494        """ Return the units and name of y- axis""" 
     
    500500        Construct a set of unique labels for a collection of plottables of 
    501501        the same type. 
    502          
     502 
    503503        Returns a map from plottable to name. 
    504          
     504 
    505505        """ 
    506506        n = len(collection) 
    507         map = {} 
     507        label_dict = {} 
    508508        if n > 0: 
    509509            basename = str(cls).split('.')[-1] 
    510510            if n == 1: 
    511                 map[collection[0]] = basename 
     511                label_dict[collection[0]] = basename 
    512512            else: 
    513513                for i in xrange(len(collection)): 
    514                     map[collection[i]] = "%s %d" % (basename, i) 
    515         return map 
    516  
    517     ##Use the following if @classmethod doesn't work 
     514                    label_dict[collection[i]] = "%s %d" % (basename, i) 
     515        return label_dict 
     516 
     517    # #Use the following if @classmethod doesn't work 
    518518    # labels = classmethod(labels) 
    519519    def setLabel(self, labelx, labely): 
    520520        """ 
    521521        It takes a label of the x and y transformation and set View parameters 
    522          
     522 
    523523        :param transx: The label of x transformation is sent by Properties Dialog 
    524524        :param transy: The label of y transformation is sent Properties Dialog 
    525          
     525 
    526526        """ 
    527527        self.view.xLabel = labelx 
    528528        self.view.yLabel = labely 
    529      
     529 
    530530    def set_View(self, x, y): 
    531531        """Load View""" 
     
    533533        self.y = y 
    534534        self.reset_view() 
    535          
     535 
    536536    def reset_view(self): 
    537537        """Reload view with new value to plot""" 
     
    541541        self.view.DXreel = self.view.dx 
    542542        self.view.DYreel = self.view.dy 
    543          
     543 
    544544    def render(self, plot): 
    545545        """ 
    546546        The base class makes sure the correct units are being used for 
    547547        subsequent plottable. 
    548          
     548 
    549549        For now it is assumed that the graphs are commensurate, and if you 
    550         put a Qx object on a Temperature graph then you had better hope  
     550        put a Qx object on a Temperature graph then you had better hope 
    551551        that it makes sense. 
    552          
     552 
    553553        """ 
    554554        plot.xaxis(self._xaxis, self._xunit) 
    555555        plot.yaxis(self._yaxis, self._yunit) 
    556          
     556 
    557557    def is_empty(self): 
    558558        """ 
     
    563563            return True 
    564564        return False 
    565          
     565 
    566566    def colors(self): 
    567567        """Return the number of colors need to render the object""" 
    568568        return 1 
    569      
     569 
    570570    def transformView(self): 
    571571        """ 
     
    573573        """ 
    574574        self.view.transform(self.x, self.y, self.dx, self.dy) 
    575          
     575 
    576576    def returnValuesOfView(self): 
    577577        """ 
     
    579579        """ 
    580580        return self.view.returnXview() 
    581      
     581 
    582582    def check_data_PlottableX(self): 
    583583        """ 
     
    586586        """ 
    587587        self.view.check_data_logX() 
    588          
     588 
    589589    def check_data_PlottableY(self): 
    590590        """ 
    591         Since no transformation is made for log10(y), check that  
     591        Since no transformation is made for log10(y), check that 
    592592        no negative values is plot in log scale 
    593593        """ 
    594594        self.view.check_data_logY() 
    595          
     595 
    596596    def transformX(self, transx, transdx): 
    597597        """ 
    598598        Receive pointers to function that transform x and dx 
    599599        and set corresponding View pointers 
    600          
     600 
    601601        :param transx: pointer to function that transforms x 
    602602        :param transdx: pointer to function that transforms dx 
    603          
     603 
    604604        """ 
    605605        self.view.setTransformX(transx, transdx) 
    606          
     606 
    607607    def transformY(self, transy, transdy): 
    608608        """ 
    609609        Receive pointers to function that transform y and dy 
    610610        and set corresponding View pointers 
    611          
     611 
    612612        :param transy: pointer to function that transforms y 
    613613        :param transdy: pointer to function that transforms dy 
    614          
     614 
    615615        """ 
    616616        self.view.setTransformY(transy, transdy) 
    617          
     617 
    618618    def onReset(self): 
    619619        """ 
     
    621621        """ 
    622622        self.view.onResetView() 
    623          
     623 
    624624    def onFitRange(self, xmin=None, xmax=None): 
    625625        """ 
    626626        It limits View data range to plot from min to max 
    627          
     627 
    628628        :param xmin: the minimum value of x to plot. 
    629629        :param xmax: the maximum value of x to plot 
    630          
     630 
    631631        """ 
    632632        self.view.onFitRangeView(xmin, xmax) 
    633      
    634      
    635 class View: 
     633 
     634 
     635class View(object): 
    636636    """ 
    637637    Representation of the data that might include a transformation 
     
    672672        :param dx: array of  errors values on x 
    673673        :param dy: array of error values on y 
    674          
     674 
    675675        """ 
    676676        # Sanity check 
     
    678678        has_err_x = not (dx == None or len(dx) == 0) 
    679679        has_err_y = not (dy == None or len(dy) == 0) 
    680          
     680 
    681681        if(x != None) and (y != None): 
    682682            if not dx == None and not len(dx) == 0 and not len(x) == len(dx): 
     
    689689                msg += "and x are not of the same length" 
    690690                raise ValueError, msg 
    691          
     691 
    692692            if not dy == None and not len(dy) == 0 and not len(y) == len(dy): 
    693693                msg = "Plottable.View: Given y and dy are not of the same " 
     
    750750            self.DXreel = self.dx 
    751751            self.DYreel = self.dy 
    752                  
     752 
    753753    def onResetView(self): 
    754754        """ 
     
    760760        self.dx = self.DXreel 
    761761        self.dy = self.DYreel 
    762          
     762 
    763763    def setTransformX(self, funcx, funcdx): 
    764764        """ 
    765765        Receive pointers to function that transform x and dx 
    766766        and set corresponding View pointers 
    767          
     767 
    768768        :param transx: pointer to function that transforms x 
    769769        :param transdx: pointer to function that transforms dx 
     
    771771        self.funcx = funcx 
    772772        self.funcdx = funcdx 
    773          
     773 
    774774    def setTransformY(self, funcy, funcdy): 
    775775        """ 
    776776        Receive pointers to function that transform y and dy 
    777777        and set corresponding View pointers 
    778          
     778 
    779779        :param transx: pointer to function that transforms y 
    780780        :param transdx: pointer to function that transforms dy 
     
    782782        self.funcy = funcy 
    783783        self.funcdy = funcdy 
    784     
     784 
    785785    def returnXview(self): 
    786786        """ 
     
    788788        """ 
    789789        return self.x, self.y, self.dx, self.dy 
    790      
     790 
    791791    def check_data_logX(self): 
    792792        """ 
     
    805805            for i in range(len(self.x)): 
    806806                try: 
    807                     if (self.x[i] > 0): 
     807                    if self.x[i] > 0: 
    808808                        tempx.append(self.x[i]) 
    809809                        tempdx.append(self.dx[i]) 
     
    811811                        tempdy.append(self.dy[i]) 
    812812                except: 
    813                     print "check_data_logX: skipping point x %g" % self.x[i] 
    814                     print sys.exc_value 
    815                     pass  
     813                    logging.error("check_data_logX: skipping point x %g", self.x[i]) 
     814                    logging.error(sys.exc_value) 
    816815            self.x = tempx 
    817816            self.y = tempy 
    818817            self.dx = tempdx 
    819818            self.dy = tempdy 
    820          
     819 
    821820    def check_data_logY(self): 
    822821        """ 
    823822        Remove negative value in y vector 
    824823        to avoid plotting negative value of Log10 
    825          
     824 
    826825        """ 
    827826        tempx = [] 
     
    833832        if self.dy == None: 
    834833            self.dy = numpy.zeros(len(self.y)) 
    835         if (self.yLabel == "log10(y)"): 
     834        if self.yLabel == "log10(y)": 
    836835            for i in range(len(self.x)): 
    837836                try: 
    838                     if (self.y[i] > 0): 
     837                    if self.y[i] > 0: 
    839838                        tempx.append(self.x[i]) 
    840839                        tempdx.append(self.dx[i]) 
     
    842841                        tempdy.append(self.dy[i]) 
    843842                except: 
    844                     print "check_data_logY: skipping point %g" % self.y[i] 
    845                     print sys.exc_value 
    846                     pass 
     843                    logging.error("check_data_logY: skipping point %g", self.y[i]) 
     844                    logging.error(sys.exc_value) 
     845 
    847846            self.x = tempx 
    848847            self.y = tempy 
    849848            self.dx = tempdx 
    850849            self.dy = tempdy 
    851              
     850 
    852851    def onFitRangeView(self, xmin=None, xmax=None): 
    853852        """ 
    854853        It limits View data range to plot from min to max 
    855          
     854 
    856855        :param xmin: the minimum value of x to plot. 
    857856        :param xmax: the maximum value of x to plot 
    858          
     857 
    859858        """ 
    860859        tempx = [] 
     
    866865        if self.dy == None: 
    867866            self.dy = numpy.zeros(len(self.y)) 
    868         if (xmin != None) and (xmax != None): 
     867        if xmin != None and xmax != None: 
    869868            for i in range(len(self.x)): 
    870                 if (self.x[i] >= xmin) and (self.x[i] <= xmax): 
     869                if self.x[i] >= xmin and self.x[i] <= xmax: 
    871870                    tempx.append(self.x[i]) 
    872871                    tempdx.append(self.dx[i]) 
     
    878877            self.dy = tempdy 
    879878 
    880                
     879 
    881880class Data2D(Plottable): 
    882881    """ 
     
    884883    """ 
    885884    def __init__(self, image=None, qx_data=None, qy_data=None, 
    886                   err_image=None, xmin=None, xmax=None, ymin=None, 
    887                   ymax=None, zmin=None, zmax=None): 
     885                 err_image=None, xmin=None, xmax=None, ymin=None, 
     886                 ymax=None, zmin=None, zmax=None): 
    888887        """ 
    889888        Draw image 
     
    898897        self.source = None 
    899898        self.detector = [] 
    900      
    901         ## Units for Q-values 
     899 
     900        # # Units for Q-values 
    902901        self.xy_unit = 'A^{-1}' 
    903         ## Units for I(Q) values 
     902        # # Units for I(Q) values 
    904903        self.z_unit = 'cm^{-1}' 
    905904        self._zaxis = '' 
     
    910909        self._yaxis = '\\rm{Q_{y}}' 
    911910        self._yunit = 'A^{-1}' 
    912          
    913         ### might remove that later 
    914         ## Vector of Q-values at the center of each bin in x 
     911 
     912        # ## might remove that later 
     913        # # Vector of Q-values at the center of each bin in x 
    915914        self.x_bins = [] 
    916         ## Vector of Q-values at the center of each bin in y 
     915        # # Vector of Q-values at the center of each bin in y 
    917916        self.y_bins = [] 
    918          
    919         #x and y boundaries 
     917 
     918        # x and y boundaries 
    920919        self.xmin = xmin 
    921920        self.xmax = xmax 
    922921        self.ymin = ymin 
    923922        self.ymax = ymax 
    924          
     923 
    925924        self.zmin = zmin 
    926925        self.zmax = zmax 
    927926        self.id = None 
    928          
     927 
    929928    def xaxis(self, label, unit): 
    930929        """ 
    931930        set x-axis 
    932          
     931 
    933932        :param label: x-axis label 
    934933        :param unit: x-axis unit 
    935          
     934 
    936935        """ 
    937936        self._xaxis = label 
    938937        self._xunit = unit 
    939          
     938 
    940939    def yaxis(self, label, unit): 
    941940        """ 
    942941        set y-axis 
    943          
     942 
    944943        :param label: y-axis label 
    945944        :param unit: y-axis unit 
    946          
     945 
    947946        """ 
    948947        self._yaxis = label 
    949948        self._yunit = unit 
    950          
     949 
    951950    def zaxis(self, label, unit): 
    952951        """ 
    953952        set z-axis 
    954          
     953 
    955954        :param label: z-axis label 
    956955        :param unit: z-axis unit 
    957          
     956 
    958957        """ 
    959958        self._zaxis = label 
    960959        self._zunit = unit 
    961          
     960 
    962961    def setValues(self, datainfo=None): 
    963962        """ 
    964963        Use datainfo object to initialize data2D 
    965          
     964 
    966965        :param datainfo: object 
    967          
     966 
    968967        """ 
    969968        self.image = copy.deepcopy(datainfo.data) 
     
    971970        self.qy_data = copy.deepcopy(datainfo.qy_data) 
    972971        self.err_image = copy.deepcopy(datainfo.err_data) 
    973          
     972 
    974973        self.xy_unit = datainfo.Q_unit 
    975974        self.z_unit = datainfo.I_unit 
    976975        self._zaxis = datainfo._zaxis 
    977         
     976 
    978977        self.xaxis(datainfo._xunit, datainfo._xaxis) 
    979978        self.yaxis(datainfo._yunit, datainfo._yaxis) 
    980         #x and y boundaries 
     979        # x and y boundaries 
    981980        self.xmin = datainfo.xmin 
    982981        self.xmax = datainfo.xmax 
    983982        self.ymin = datainfo.ymin 
    984983        self.ymax = datainfo.ymax 
    985         ## Vector of Q-values at the center of each bin in x 
     984        # # Vector of Q-values at the center of each bin in x 
    986985        self.x_bins = datainfo.x_bins 
    987         ## Vector of Q-values at the center of each bin in y 
     986        # # Vector of Q-values at the center of each bin in y 
    988987        self.y_bins = datainfo.y_bins 
    989          
     988 
    990989    def set_zrange(self, zmin=None, zmax=None): 
    991990        """ 
     
    996995        else: 
    997996            raise "zmin is greater or equal to zmax " 
    998          
     997 
    999998    def render(self, plot, **kw): 
    1000999        """ 
    10011000        Renders the plottable on the graph 
    1002          
     1001 
    10031002        """ 
    10041003        plot.image(self.data, self.qx_data, self.qy_data, 
    10051004                   self.xmin, self.xmax, self.ymin, 
    10061005                   self.ymax, self.zmin, self.zmax, **kw) 
    1007         
     1006 
    10081007    def changed(self): 
    10091008        """ 
    10101009        """ 
    10111010        return False 
    1012      
     1011 
    10131012    @classmethod 
    10141013    def labels(cls, collection): 
    10151014        """Build a label mostly unique within a collection""" 
    1016         map = {} 
     1015        label_dict = {} 
    10171016        for item in collection: 
    1018             #map[item] = label(item, collection) 
    1019             #map[item] = r"$\rm{%s}$" % item.name 
    10201017            if item.label == "Data2D": 
    10211018                item.label = item.name 
    1022             map[item] = item.label 
    1023         return map 
     1019            label_dict[item] = item.label 
     1020        return label_dict 
    10241021 
    10251022 
     
    10281025    Data plottable: scatter plot of x,y with errors in x and y. 
    10291026    """ 
    1030      
     1027 
    10311028    def __init__(self, x, y, dx=None, dy=None): 
    10321029        """ 
     
    10561053        self.zorder = 1 
    10571054        self.hide_error = False 
    1058        
     1055 
    10591056    def render(self, plot, **kw): 
    10601057        """ 
     
    10681065            plot.interactive_points(self.view.x, self.view.y, 
    10691066                                    dx=self.view.dx, dy=self.view.dy, 
    1070               name=self.name, zorder=self.zorder, **kw) 
     1067                                    name=self.name, zorder=self.zorder, **kw) 
    10711068        else: 
    1072             kw['id'] =  self.id 
     1069            kw['id'] = self.id 
    10731070            kw['hide_error'] = self.hide_error 
    10741071            kw['symbol'] = self.symbol 
     
    10761073            kw['markersize'] = self.markersize 
    10771074            plot.points(self.view.x, self.view.y, dx=self.view.dx, 
    1078                 dy=self.view.dy, zorder=self.zorder,  
    1079                 marker=self.symbollist[self.symbol], **kw) 
    1080         
     1075                        dy=self.view.dy, zorder=self.zorder, 
     1076                        marker=self.symbollist[self.symbol], **kw) 
     1077 
    10811078    def changed(self): 
    10821079        return False 
     
    10851082    def labels(cls, collection): 
    10861083        """Build a label mostly unique within a collection""" 
    1087         map = {} 
     1084        label_dict = {} 
    10881085        for item in collection: 
    1089             #map[item] = label(item, collection) 
    1090             #map[item] = r"$\rm{%s}$" % item.name 
    10911086            if item.label == "data": 
    10921087                item.label = item.name 
    1093             map[item] = item.label 
    1094         return map 
    1095      
    1096      
     1088            label_dict[item] = item.label 
     1089        return label_dict 
     1090 
     1091 
    10971092class Theory1D(Plottable): 
    10981093    """ 
    10991094    Theory plottable: line plot of x,y with confidence interval y. 
    1100      
    11011095    """ 
    11021096    def __init__(self, x, y, dy=None): 
     
    11051099        Confidence intervals in x are given by dx[i] or by (xlo[i],xhi[i]) 
    11061100        if the limits are asymmetric. 
    1107          
     1101 
    11081102        The title is the name that will show up on the legend. 
    11091103        """ 
    11101104        Plottable.__init__(self) 
    1111         msg = "Theory1D is no longer supported, please use Data1D and change" 
    1112         msg += " symbol.\n" 
     1105        msg = "Theory1D is no longer supported, please use Data1D and change symbol.\n" 
    11131106        raise DeprecationWarning, msg 
    1114         self.name = "theory" 
    1115         self.label = "theory" 
    1116         self.x = x 
    1117         self.y = y 
    1118         self.dy = dy 
    1119         self.xaxis('', '') 
    1120         self.yaxis('', '') 
    1121         self.view = View(self.x, self.y, None, self.dy) 
    1122         self.symbol = 0 
    1123         self.id = None 
    1124         self.zorder = 10 
    1125          
    1126     def render(self, plot, **kw): 
    1127         """ 
    1128         """ 
    1129         if self.interactive == True: 
    1130             kw['id'] = self.id 
    1131             plot.interactive_curve(self.view.x, self.view.y, 
    1132                                    dy=self.view.dy, 
    1133                                    name=self.name, zorder=self.zorder, **kw) 
    1134         else: 
    1135             kw['id'] = self.id 
    1136             plot.curve(self.view.x, self.view.y, dy=self.view.dy,  
    1137                        zorder=self.zorder, **kw) 
    1138              
    1139     def changed(self): 
    1140         return False 
    1141      
    1142     @classmethod 
    1143     def labels(cls, collection): 
    1144         """Build a label mostly unique within a collection""" 
    1145         map = {} 
    1146         for item in collection: 
    1147             if item.label == "theory": 
    1148                 item.label = item.name 
    1149             map[item] = item.label 
    1150         return map 
    1151     
    1152     
     1107 
    11531108class Fit1D(Plottable): 
    11541109    """ 
     
    11591114 
    11601115    The color of the data and theory will be shared. 
    1161      
     1116 
    11621117    """ 
    11631118    def __init__(self, data=None, theory=None): 
     
    11941149        self.xpos = xpos 
    11951150        self.ypos = ypos 
    1196          
     1151 
    11971152    def render(self, plot, **kw): 
    11981153        """ 
     
    12061161                          self.text, 
    12071162                          label=self.name, 
    1208                           transform=xcoords, 
    1209                           ) 
    1210              
     1163                          transform=xcoords) 
     1164 
    12111165    def setText(self, text): 
    12121166        """Set the text string.""" 
     
    12301184        """ 
    12311185        self.ypos = y 
    1232       
     1186 
    12331187 
    12341188# --------------------------------------------------------------- 
     
    12441198        Plottable.__init__(self) 
    12451199        self.name = "chisq" 
    1246         #super( Chisq, self).__init__(None, None, None, None) 
    12471200        self._chisq = chisq 
    12481201        self.xpos = 0.5 
    12491202        self.ypos = 0.9 
    1250          
     1203 
    12511204    def render(self, plot, **kw): 
    12521205        """ 
     
    12601213 
    12611214        xcoords = transforms.blended_transform_factory(plot.subplot.transAxes, 
    1262                                                      plot.subplot.transAxes) 
     1215                                                      plot.subplot.transAxes) 
    12631216        plot.subplot.text(self.xpos, 
    12641217                          self.ypos, 
    12651218                          chisqTxt, label='chisq', 
    1266                           transform=xcoords,) 
    1267              
     1219                          transform=xcoords) 
     1220 
    12681221    def setChisq(self, chisq): 
    12691222        """ 
     
    12771230def sample_graph(): 
    12781231    import numpy as nx 
    1279      
     1232 
    12801233    # Construct a simple graph 
    12811234    if False: 
    1282         x = nx.array([1,2,3,4,5,6], 'd') 
    1283         y = nx.array([4,5,6,5,4,5], 'd') 
     1235        x = nx.array([1, 2, 3, 4, 5, 6], 'd') 
     1236        y = nx.array([4, 5, 6, 5, 4, 5], 'd') 
    12841237        dy = nx.array([0.2, 0.3, 0.1, 0.2, 0.9, 0.3]) 
    12851238    else: 
     
    13001253    import wx 
    13011254    from pylab_plottables import Plotter 
    1302     #from mplplotter import Plotter 
     1255    # from mplplotter import Plotter 
    13031256 
    13041257    # Make a frame to show it 
     
    13101263    # render the graph to the pylab plotter 
    13111264    graph.render(plotter) 
    1312      
    1313     class GraphUpdate: 
     1265 
     1266    class GraphUpdate(object): 
    13141267        callnum = 0 
    1315          
     1268 
    13161269        def __init__(self, graph, plotter): 
    13171270            self.graph, self.plotter = graph, plotter 
    1318          
     1271 
    13191272        def __call__(self): 
    13201273            if self.graph.changed(): 
     
    13221275                return True 
    13231276            return False 
    1324          
     1277 
    13251278        def onIdle(self, event): 
    13261279            self.callnum = self.callnum + 1 
    1327             if self.__call__():  
     1280            if self.__call__(): 
    13281281                pass  # event.RequestMore() 
    13291282    update = GraphUpdate(graph, plotter) 
Note: See TracChangeset for help on using the changeset viewer.