Changeset cafa75f in sasview


Ignore:
Timestamp:
Apr 2, 2014 4:04:01 PM (10 years ago)
Author:
pkienzle
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:
1829835
Parents:
6771d94
Message:

support old and new versions of matplotlib

Location:
src/sans
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/sans/guiframe/local_perspectives/plotting/Plotter1D.py

    rb9f6d83 rcafa75f  
    173173        self.graph.reset() 
    174174        self.plots      = {} 
    175         if self.is_zoomed: 
    176             self.is_zoomed = False 
     175        self.is_zoomed = False 
    177176         
    178177    def _OnReSize(self, event):    
     
    480479            try: 
    481480                self._onEVT_FUNC_PROPERTY() 
    482             except: 
     481            except Exception, exc: 
    483482                msg=" Encountered singular points..." 
    484483                wx.PostEvent(self.parent, StatusEvent(status=\ 
    485                     "Plotting Error: %s"% msg, info="error"))  
    486             # Check if zoomed 
    487             try: tb = self.toolbar.wx_ids['Back'] 
    488             except AttributeError: tb = self.toolbar._NTB2_BACK # Cruft 
    489             toolbar_zoomed = self.toolbar.GetToolEnabled(tb) 
    490             if self.is_zoomed or toolbar_zoomed: 
     484                    "Plotting Error: %s"% str(exc), info="error")) 
     485            if self.is_zoomed: 
    491486                # Recover the x,y limits 
    492487                self.subplot.set_xlim((xlo, xhi))      
     
    502497                    # MAC: forcing to plot 2D avg 
    503498                    self.canvas._onDrawIdle() 
    504             except: 
     499            except Exception,exc: 
    505500                msg=" Encountered singular points..." 
    506501                wx.PostEvent(self.parent, StatusEvent(status=\ 
    507                     "Plotting Error: %s"% msg, info="error"))  
     502                    "Plotting Error: %s"% str(exc), info="error")) 
    508503            self.toolbar.update() 
    509             if self.is_zoomed: 
    510                 self.is_zoomed = False 
     504            self.is_zoomed = False 
    511505            # Update Graph menu and help string         
    512506            #pos = self.parent._window_menu.FindItem(self.window_caption) 
     
    566560        self.graph.render(self) 
    567561        self.subplot.figure.canvas.draw_idle()   
    568         # Check if zoomed 
    569         try: tb = self.toolbar.wx_ids['Back'] 
    570         except AttributeError: tb = self.toolbar._NTB2_BACK # Cruft 
    571         toolbar_zoomed = self.toolbar.GetToolEnabled(tb) 
    572         if self.is_zoomed or toolbar_zoomed: 
     562        if self.is_zoomed: 
    573563            # Recover the x,y limits 
    574564            self.subplot.set_xlim((xlo, xhi))      
  • src/sans/guiframe/local_perspectives/plotting/Plotter2D.py

    rb9f6d83 rcafa75f  
    249249        self.default_zmin_ctl = self.zmin_2D 
    250250        self.default_zmax_ctl = self.zmax_2D 
    251         # Check if zoomed 
    252         try: tb = self.toolbar.wx_ids['Back'] 
    253         except AttributeError: tb = self.toolbar._NTB2_BACK # Cruft 
    254         toolbar_zoomed = self.toolbar.GetToolEnabled(tb) 
    255         if not self.is_zoomed and not toolbar_zoomed: 
     251        if not self.is_zoomed: 
    256252            return 
    257253        # Recover the x,y limits 
     
    263259            else:  
    264260                self.toolbar.update() 
    265                 self._is_zoomed = False 
     261                self.is_zoomed = False 
    266262 
    267263    def _set_axis_labels(self): 
  • src/sans/plottools/PlotPanel.py

    reddb6ec rcafa75f  
    33import logging 
    44import wx 
    5 import os 
    65# Try a normal import first 
    76# If it fails, try specifying a version 
     
    1211from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg 
    1312from matplotlib.figure import Figure 
    14 from sans.plottools import transform 
    15 from sans.plottools.plottables import Data1D 
    16 from sans.plottools.binder import BindArtist 
     13import os 
     14import transform 
     15from plottables import Data1D 
     16#TODO: make the plottables interactive 
     17from binder import BindArtist 
    1718from matplotlib.font_manager import FontProperties 
    1819DEBUG = False 
    1920 
    20 from sans.plottools.plottables import Graph 
    21 from sans.plottools.TextDialog import TextDialog 
    22 from sans.plottools.LabelDialog import LabelDialog 
     21from plottables import Graph 
     22from plottables import Text 
     23from TextDialog import TextDialog 
     24from LabelDialog import LabelDialog 
    2325import operator 
    2426 
     
    3638        for a in obj.get_children(): show_tree(a, d+1) 
    3739      
    38 from sans.plottools.unitConverter import UnitConvertion as convertUnit 
     40from unitConverter import UnitConvertion as convertUnit 
    3941 
    4042 
    4143def _rescale(lo, hi, step, pt=None, bal=None, scale='linear'): 
    42     """ 
    43     Rescale (lo,hi) by step, returning the new (lo,hi) 
    44     The scaling is centered on pt, with positive values of step 
    45     driving lo/hi away from pt and negative values pulling them in. 
    46     If bal is given instead of point, it is already in [0,1] coordinates. 
     44        """ 
     45        Rescale (lo,hi) by step, returning the new (lo,hi) 
     46        The scaling is centered on pt, with positive values of step 
     47        driving lo/hi away from pt and negative values pulling them in. 
     48        If bal is given instead of point, it is already in [0,1] coordinates. 
    4749     
    48     This is a helper function for step-based zooming. 
    49     """ 
    50     # Convert values into the correct scale for a linear transformation 
    51     # TODO: use proper scale transformers 
    52     loprev = lo 
    53     hiprev = hi 
    54     if scale == 'log': 
    55         assert lo > 0 
    56         if lo > 0: 
    57             lo = math.log10(lo) 
    58         if hi > 0: 
    59             hi = math.log10(hi) 
    60         if pt is not None: 
    61             pt = math.log10(pt) 
     50        This is a helper function for step-based zooming. 
     51         
     52        """ 
     53        # Convert values into the correct scale for a linear transformation 
     54        # TODO: use proper scale transformers 
     55        loprev = lo 
     56        hiprev = hi 
     57        if scale == 'log': 
     58            assert lo > 0 
     59            if lo > 0: 
     60                lo = math.log10(lo) 
     61            if hi > 0: 
     62                hi = math.log10(hi) 
     63            if pt is not None: 
     64                pt = math.log10(pt) 
     65         
     66        # Compute delta from axis range * %, or 1-% if persent is negative 
     67        if step > 0: 
     68            delta = float(hi - lo) * step / 100 
     69        else: 
     70            delta = float(hi - lo) * step / (100 - step) 
    6271     
    63     # Compute delta from axis range * %, or 1-% if present is negative 
    64     if step > 0: 
    65         delta = float(hi - lo) * step / 100 
    66     else: 
    67         delta = float(hi - lo) * step / (100 - step) 
    68  
    69     # Add scale factor proportionally to the lo and hi values, 
    70     # preserving the 
    71     # point under the mouse 
    72     if bal is None: 
    73         bal = float(pt - lo) / (hi - lo) 
    74     lo = lo - (bal * delta) 
    75     hi = hi + (1 - bal) * delta 
    76  
    77     # Convert transformed values back to the original scale 
    78     if scale == 'log': 
    79         if (lo <= -250) or (hi >= 250): 
    80             lo = loprev 
    81             hi = hiprev 
    82         else: 
    83             lo, hi = math.pow(10., lo), math.pow(10., hi) 
    84     return (lo, hi) 
     72        # Add scale factor proportionally to the lo and hi values, 
     73        # preserving the 
     74        # point under the mouse 
     75        if bal is None: 
     76            bal = float(pt - lo) / (hi - lo) 
     77        lo = lo - (bal * delta) 
     78        hi = hi + (1 - bal) * delta 
     79     
     80        # Convert transformed values back to the original scale 
     81        if scale == 'log': 
     82            if (lo <= -250) or (hi >= 250): 
     83                lo = loprev 
     84                hi = hiprev 
     85            else: 
     86                lo, hi = math.pow(10., lo), math.pow(10., hi) 
     87        return (lo, hi) 
    8588 
    8689 
     
    122125        self.figure = Figure(None, dpi, linewidth=2.0) 
    123126        self.color = '#b3b3b3' 
    124         from sans.plottools.canvas import FigureCanvas 
     127        from canvas import FigureCanvas 
    125128        self.canvas = FigureCanvas(self, -1, self.figure) 
    126129        self.SetColor(color) 
     
    155158         
    156159        # Define some constants 
    157         self.colorlist = ['b', 'g', 'r', 'c', 'm', 'y', 'k'] 
    158         self.symbollist = ['o', 'x', '^', 'v', '<', '>', '+', 
    159                            's', 'd', 'D', 'h', 'H', 'p', '-'] 
     160        self.colorlist = ['b','g','r','c','m','y','k'] 
     161        self.symbollist = ['o','x','^','v','<','>','+', 
     162                           's','d','D','h','H','p', '-'] 
    160163         
    161164        #List of texts currently on the plot 
     
    972975            self.line_collections_list = handles2 
    973976            self.legend = self.subplot.legend(handles2, labels2, 
    974                             prop=FontProperties(size=10), numpoints=1, 
    975                             handletextsep=.05, loc=self.legendLoc) 
     977                            prop=FontProperties(size=10), 
     978                            loc=self.legendLoc) 
    976979            if self.legend != None: 
    977980                self.legend.set_picker(self.legend_picker) 
     
    10031006        self.line_collections_list = handles2 
    10041007        self.legend = self.subplot.legend(handles2, labels2, 
    1005                             prop=FontProperties(size=10), numpoints=1, 
    1006                             handletextsep=.05, loc=self.legendLoc) 
     1008                            prop=FontProperties(size=10), 
     1009                            loc=self.legendLoc) 
    10071010        if self.legend != None: 
    10081011            self.legend.set_picker(self.legend_picker) 
     
    11031106        ## Set the view scale for all plots 
    11041107        self._onEVT_FUNC_PROPERTY(False) 
    1105         # Check if zoomed 
    1106         try: tb = self.toolbar.wx_ids['Back'] 
    1107         except AttributeError: tb = self.toolbar._NTB2_BACK # Cruft 
    1108         toolbar_zoomed = self.toolbar.GetToolEnabled(tb) 
    1109  
    1110         if self.is_zoomed or toolbar_zoomed: 
     1108        if self.is_zoomed: 
    11111109            # Recover the x,y limits 
    11121110            self.subplot.set_xlim((xlo, xhi)) 
    11131111            self.subplot.set_ylim((ylo, yhi)) 
     1112 
     1113    @property 
     1114    def is_zoomed(self): 
     1115        if hasattr(self.toolbar, "wx_ids"): 
     1116            back = self.toolbar.wx_ids['Back'] 
     1117        else: # CRUFT 
     1118            back = self.toolbar._NTB2_BACK 
     1119        toolbar_zoomed = self.toolbar.GetToolEnabled(back) 
     1120        return self._is_zoomed or toolbar_zoomed 
     1121 
     1122    @is_zoomed.setter 
     1123    def is_zoomed(self, value): 
     1124        self._is_zoomed = value 
    11141125                    
    11151126    def _on_yaxis_label(self, event): 
     
    12591270                handles2, labels2 = zip(*hl) 
    12601271                self.line_collections_list = handles2 
    1261                 try: 
    1262                     self.legend = ax.legend(handles2, labels2, numpoints=1, 
     1272                self.legend = ax.legend(handles2, labels2, 
    12631273                                prop=FontProperties(size=10), 
    1264                                 handletextsep=.05, loc=self.legendLoc) 
    1265                 except TypeError:  # Cruft 
    1266                     # older MPL uses handletextsep instead of handletextpad 
    1267                     self.legend = ax.legend(handles2, labels2, numpoints=1, 
    1268                                 prop=FontProperties(size=10), 
    1269                                 handletextsep=.05, loc=self.legendLoc) 
     1274                                loc=self.legendLoc) 
    12701275                if self.legend != None: 
    12711276                    self.legend.set_picker(self.legend_picker) 
     
    12741279                 
    12751280            except: 
    1276                 try: 
    1277                     self.legend = ax.legend(prop=FontProperties(size=10), 
    1278                                         numpoints=1, handletextpad=.05, 
    1279                                         loc=self.legendLoc) 
    1280                 except TypeError:  # Cruft 
    1281                     # older MPL uses handletextsep instead of handletextpad 
    1282                     self.legend = ax.legend(prop=FontProperties(size=10), 
    1283                                         numpoints=1, handletextsep=.05, 
     1281                self.legend = ax.legend(prop=FontProperties(size=10), 
    12841282                                        loc=self.legendLoc) 
    12851283                 
     
    18941892                self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname), 
    18951893                                               "%s%s" % (yunits, xunits)) 
    1896             if(self.viewModel == "Kratky y*x^(2) vs x"): 
    1897                 item.transformY(transform.toYX2, transform.errToYX2) 
    1898                 self.graph._yaxis_transformed("%s \ \ %s^{2}" % (yname, xname), 
    1899                                                "%s%s" % (yunits, xunits))                 
    1900                  
    19011894            item.transformView() 
    19021895   
     
    19971990        self.graph.render(self) 
    19981991        self._onEVT_FUNC_PROPERTY(False) 
    1999         if self.is_zoomed: 
    2000                 self.is_zoomed = False 
     1992        self.is_zoomed = False 
    20011993        self.toolbar.update() 
    20021994         
  • src/sans/plottools/config.py

    ra9d5684 rcafa75f  
    5252    # if a backend has already been selected, make sure it is the correct one. 
    5353    raise ImportError("Matplotlib not using backend " + plot_backend) 
     54 
     55# set global plot style 
     56param = 'legend.handletextpad' 
     57if param not in matplotlib.rcParams: param = 'legend.handletextsep' 
     58matplotlib.rcParams[param] = 0.05 
     59matplotlib.rcParams['legend.numpoints'] = 1 
Note: See TracChangeset for help on using the changeset viewer.