Changeset 2479


Ignore:
Timestamp:
Sep 28, 2016 11:55:35 AM (5 years ago)
Author:
toby
Message:

Rework plotting to refresh after refinements

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r2457 r2479  
    246246        item.Enable(state)
    247247        self.SeqRefine.append(item) # save menu obj for use in self.EnableSeqRefineMenu
    248         self.Bind(wx.EVT_MENU, self.OnSeqRefine, id=item.GetId())
    249        
     248        if GSASIIpath.GetConfigValue('debug'): # allow exceptions for debugging
     249            self.Bind(wx.EVT_MENU, self.OnSeqRefine, id=item.GetId())
     250            item = parent.Append(help='', id=wx.ID_ANY, kind=wx.ITEM_NORMAL,
     251                text='Debug graphics refresh')
     252            self.Bind(wx.EVT_MENU, self.TestResetPlot, id=item.GetId())
     253
    250254    def _init_Imports(self):
    251255        '''import all the G2phase*.py & G2sfact*.py & G2pwd*.py files that
     
    37093713        '''Perform a refinement.
    37103714        Called from the Calculate/Refine menu.
    3711         '''       
     3715        '''
    37123716        Id = G2gd.GetPatternTreeItemId(self,self.root,'Sequential results')
    37133717        if Id:
     
    37433747        dlg.CenterOnParent()
    37443748        Rw = 100.00
    3745         oldId =  self.PatternTree.GetSelection()        #retain current selection
    3746         oldPath = self.GetTreeItemsList(oldId)
    3747         parentName = ''
    3748         oldName = self.PatternTree.GetItemText(oldId)
    3749         parentId = self.PatternTree.GetItemParent(oldId)
    3750         if parentId:
    3751             parentName = self.PatternTree.GetItemText(parentId)     #find the current data tree name
    3752             if 'Phases' in parentName:
    3753                 tabId = self.dataDisplay.GetSelection()
     3749        self.SaveTreeSetting()
    37543750        try:
    37553751            OK,Msg = G2stMn.Refine(self.GSASprojectfile,dlg)    #Msg is Rvals dict if Ok=True
     
    37693765            try:
    37703766                if dlg2.ShowModal() == wx.ID_OK:
    3771                     Id = 0
    37723767                    self.PatternTree.DeleteChildren(self.root)
    37733768                    self.HKL = []
    37743769                    G2IO.ProjFileOpen(self,False)
    3775                     Id =  self.root
    3776                     txt = None
    3777                     for txt in oldPath:
    3778                         Id = G2gd.GetPatternTreeItemId(self, Id, txt)
    3779                     self.PickIdText = None  #force reload of page
    3780                     if Id:
    3781                         self.PickId = Id
    3782                         self.PatternTree.SelectItem(Id)
    3783                         G2gd.MovePatternTreeToGrid(self,Id) # reload current tree item, should update current plot
     3770                    self.ResetPlots()
    37843771            finally:
    37853772                dlg2.Destroy()
    37863773        else:
    37873774            self.ErrorDialog('Refinement error',Msg)
    3788 
     3775       
     3776    def SaveTreeSetting(self):
     3777        'Save the last tree setting'
     3778        oldId =  self.PatternTree.GetSelection()        #retain current selection
     3779        oldPath = self.GetTreeItemsList(oldId)
     3780        self.lastTreeSetting = oldPath
     3781        # note that for reasons unclear, it does not seem necessary to reload the Atoms tab
     3782        #parentName = ''
     3783        #tabId = None
     3784        # parentId = self.PatternTree.GetItemParent(oldId)
     3785        # if parentId:
     3786        #     parentName = self.PatternTree.GetItemText(parentId)     #find the current data tree name
     3787        #     if 'Phases' in parentName:
     3788        #         tabId = self.dataDisplay.GetSelection()
     3789        #self.lastTreeSetting = oldPath,tabId
     3790        #GSASIIpath.IPyBreak()
     3791       
     3792    def ReloadTreeSetting(self):
     3793        'Reload the last tree setting, triggering the routine to redraw the data window and possibly a plot'
     3794        #oldPath,tabId = self.lastTreeSetting
     3795        oldPath = self.lastTreeSetting
     3796        Id = self.root
     3797        for txt in oldPath:
     3798            Id = G2gd.GetPatternTreeItemId(self, Id, txt)
     3799        self.PickIdText = None  #force reload of page
     3800        if Id:
     3801            self.PickId = Id
     3802            self.PatternTree.SelectItem(Id)
     3803            G2gd.MovePatternTreeToGrid(self,Id) # reload current tree item
     3804           
     3805    def TestResetPlot(self,event):
     3806        '''Debug code to test cleaning up plots after a refinement'''
     3807        #for i in range(self.G2plotNB.nb.GetPageCount()):
     3808        #    [self.G2plotNB.nb.GetPageText(i)
     3809        # save current tree item and (if needed) atoms tab
     3810        self.SaveTreeSetting()
     3811        self.ResetPlots()
     3812       
     3813    def ResetPlots(self):
     3814        '''This reloads the current tree item, often drawing a plot. It refreshes any plots
     3815        that have registered a refresh routine (see G2plotNB.RegisterRedrawRoutine)
     3816        and deletes all plots that have not been refreshed and
     3817        require one (see G2plotNB.SetNoDelete).
     3818        '''
     3819        lastRaisedPlotTab = self.G2plotNB.lastRaisedPlotTab # save the last page saved
     3820        #print 'lastRaisedPlotTab=',lastRaisedPlotTab
     3821        self.G2plotNB.lastRaisedPlotTab = None
     3822        # mark displayed plots as invalid
     3823        for lbl,frame in zip(self.G2plotNB.plotList,self.G2plotNB.panelList):
     3824            frame.plotInvalid = True
     3825        # reload current tree item
     3826        self.ReloadTreeSetting()
     3827        treeItemPlot = self.G2plotNB.lastRaisedPlotTab
     3828        # update other self-updating plots
     3829        for lbl,frame in zip(self.G2plotNB.plotList,self.G2plotNB.panelList):
     3830            if frame.plotInvalid and frame.replotFunction:
     3831                frame.replotFunction(*frame.replotArgs,**frame.replotKWargs)
     3832        # delete any remaining plots that are still invalid and need a refresh
     3833        for lbl,frame in zip(self.G2plotNB.plotList,self.G2plotNB.panelList):
     3834            if frame.plotInvalid and frame.plotRequiresRedraw:
     3835                self.G2plotNB.Delete(lbl)
     3836            #     print('deleting '+lbl) # debug code
     3837            # elif not frame.plotInvalid: # debug code
     3838            #     print(lbl+ ' was redrawn') # debug code
     3839        # put the previously last-raised tab on top, if present. If not, use the one corresponding to
     3840        # the last tree item to be selected
     3841        wx.CallAfter(self.G2plotNB.RaiseLastPage,lastRaisedPlotTab,treeItemPlot)
     3842       
    37893843    def OnSeqRefine(self,event):
    37903844        '''Perform a sequential refinement.
     
    38273881            try:
    38283882                if dlg.ShowModal() == wx.ID_OK:
    3829                     Id = 0
    3830 #                    self.G2plotNB.setReplotFlags() # mark all plots as old - doesn't exist!
    38313883                    self.PickIdText = None  #force reload of PickId contents
    38323884                    self.PatternTree.DeleteChildren(self.root)
     
    38353887                        self.G2plotNB.clear()
    38363888                    G2IO.ProjFileOpen(self,False)
     3889                    self.ResetPlots()
    38373890                    Id = G2gd.GetPatternTreeItemId(self,self.root,'Sequential results')
    38383891                    self.PatternTree.SelectItem(Id)
    38393892                    G2gd.MovePatternTreeToGrid(self,Id) # reload current tree item, should update current plot
    3840 #                    self.G2plotNB.replotAll() # refresh any plots not yet updated - doesn't exist!
    38413893            finally:
    38423894                dlg.Destroy()
  • trunk/GSASIIplot.py

    r2477 r2479  
    132132                             
    133133class G2PlotNoteBook(wx.Panel):
    134     'create a tabbed window for GSAS-II graphics'
     134    'create a tabbed panel to hold a GSAS-II graphics window'
    135135    def __init__(self,parent,id=-1,G2frame=None):
    136136        wx.Panel.__init__(self,parent,id=id)
     
    150150        self.plotList = []   # contains the tab label for each plot
    151151        self.panelList = []   # contains the panel object for each plot
    152         self.figList = []   # contains the figure object for each plot
    153         self.treeItem = {}  # contains the tree entry that generated a plot, indexed by the plot number
    154152        self.skipPageChange = False # set to True when no plot update is needed
    155153        self.allowZoomReset = True # this indicates plot should be updated not initialized
     154        self.lastRaisedPlotTab = None
    156155       
    157156    def OnNotebookKey(self,event):
     
    173172            pass
    174173
     174    def SetNoDelete(self,name):
     175        '''Indicate that a plot does not need to be redrawn
     176        '''
     177        if name not in self.plotList:
     178            print('Error, in SetNoDelete plot not found: '+name)
     179            return
     180        page = self.panelList[self.plotList.index(name)]
     181        page.plotRequiresRedraw = False # plot should not be deleted even if not redrawn
     182       
     183
     184    def RegisterRedrawRoutine(self,name,routine=None,args=(),kwargs={}):
     185        '''Save information to determine how to redraw a plot
     186        :param str name: label on tab of plot
     187        :param Object routine: a function to be called
     188        :param args: a list of positional parameters for the function
     189        :param kwargs: a dict with keyword parameters for the function
     190        '''
     191        if name not in self.plotList:
     192            print('Error, plot not found: '+name)
     193            return
     194        page = self.panelList[self.plotList.index(name)]
     195        page.replotFunction = routine
     196        page.replotArgs = args
     197        page.replotKWargs = kwargs
     198
     199    def GetTabIndex(self,label):
     200        '''Look up a tab label and return the index in the notebook (this appears to be
     201        independent to the order it is dragged to -- at least in Windows) as well as
     202        the associated wx.Panel
     203
     204        An exception is raised if the label is not found     
     205        '''
     206        for i in range(self.nb.GetPageCount()):
     207            if label == self.nb.GetPageText(i):
     208                return i,self.nb.GetPage(i)
     209        else:
     210            raise ValueError('Plot not found')
     211
     212    def RaiseLastPage(self,lastRaisedPlotTab,treeItemPlot):
     213        '''Raises either the Last tab clicked on or what is drawn by the selected tree item
     214        This is called after a refinement is completed by :meth:`GSASII.GSASII.ResetPlots`
     215        '''
     216        plotNum = None
     217        if lastRaisedPlotTab in self.plotList:
     218            plotNum = self.plotList.index(lastRaisedPlotTab)
     219        elif treeItemPlot in self.plotList:
     220            plotNum = self.plotList.index(treeItemPlot)
     221        if plotNum is not None:
     222            wx.CallAfter(self.SetSelectionNoRefresh,plotNum)
     223
     224    def FindPlotTab(self,label,type,newImage=True):
     225        '''Open a plot tab for initial plotting, or raise the tab if it already exists
     226        Set a flag (Page.plotInvalid) that it has been redrawn
     227        Record the name of the this plot in self.lastRaisedPlotTab
     228        '''
     229        limits = None
     230        Plot = None
     231        try:
     232            new = False
     233            plotNum,Page = self.GetTabIndex(label)
     234            if type == 'mpl' or type == '3d':         
     235                Plot = Page.figure.gca()          #get previous plot
     236                limits = Plot.get_xlim(),Plot.get_ylim() # save previous limits
     237                if newImage:
     238                    Page.figure.clf()
     239                    Plot = Page.figure.gca()          #get a fresh plot after clf()
     240            self.SetSelectionNoRefresh(plotNum) # raises plot tab
     241        except (ValueError,AttributeError):
     242            new = True
     243            if type == 'mpl':
     244                Plot = self.addMpl(label).gca()
     245            elif type == 'ogl':
     246                Plot = self.addOgl(label)
     247            elif type == '3d':
     248                Plot = mp3d.Axes3D(self.add3D(label))
     249            plotNum = self.plotList.index(label)
     250            Page = self.nb.GetPage(plotNum)
     251
     252        Page.plotInvalid = False # plot has just been drawn
     253        self.lastRaisedPlotTab = label
     254        self.RaisePageNoRefresh(Page)
     255        return new,plotNum,Page,Plot,limits
     256   
    175257    def _addPage(self,name,page):
    176         'Add the newly created page to the notebook and associated lists'
     258        '''Add the newly created page to the notebook and associated lists.
     259        :param name: the label placed on the tab, which should be unique
     260        :param page: the wx.Frame for the matplotlib, openGL, etc. window
     261        '''
    177262        self.skipPageChange = True
    178         self.nb.AddPage(page,name)       
    179         self.plotList.append(name)
     263        if name in self.plotList:
     264            print('Warning: duplicate plot name! Name='+name)
     265        self.nb.AddPage(page,name)
     266        self.plotList.append(name) # used to lookup plot in self.panelList
     267        # Note that order in lists make not agree with actual tab order; use self.nb.GetPageText(i)
     268        #    where (self=G2plotNB) for latter
    180269        self.panelList.append(page) # panel object for plot
    181         self.figList.append(page.figure)  # figure object for plot
     270        self.lastRaisedPlotTab = name
     271        page.plotInvalid = False # plot has just been drawn
     272        page.plotRequiresRedraw = True # set to False if plot should be retained even if not refreshed
     273        page.replotFunction = None # used to specify a routine to redraw the routine
     274        page.replotArgs = []
     275        page.replotKWargs = {}
    182276        self.skipPageChange = False
    183 #        self._registerTreeItem(name)
    184 
    185     def _registerTreeItem(self,plotLabel):      #disabled for now
    186         '''Save the name of the of the data tree item that has generated the plot
    187         and for phases, save the name of the generating tab (at present that is not used)
    188         '''
    189         tree = self.G2frame.PatternTree
    190         self.treeItem[plotLabel] = [tree._getTreeItemsList(tree.GetSelection()),'']
    191         if len(self.treeItem[plotLabel]) == 2 and self.treeItem[plotLabel][0][0] == 'Phases':
    192             self.treeItem[plotLabel][1] = self.G2frame.dataDisplayPhaseText
    193277               
    194278    def addMpl(self,name=""):
     
    217301            del self.plotList[item]
    218302            del self.panelList[item]
    219             del self.figList[item]
    220303            self.nb.DeletePage(item)
    221304        except ValueError:          #no plot of this name - do nothing
     
    228311        self.plotList = []
    229312        self.panelList = []
    230         self.figList = []
    231313        self.status.DestroyChildren()
    232314       
     
    255337        Page.SetFocus()
    256338        self.skipPageChange = False
    257                                  
     339
    258340    def OnPageChanged(self,event):
    259341        '''respond to someone pressing a tab on the plot window.
     
    264346        '''
    265347        tabLabel = event.GetEventObject().GetPageText(event.GetSelection())
     348        self.lastRaisedPlotTab = tabLabel
    266349        if plotDebug:
    267350            print 'PageChanged, self=',str(self).split('0x')[1],tabLabel,self.skipPageChange
     
    270353        self.status.SetFields(['',''])  # clear old status message
    271354        self.status.SetStatusWidths([150,-1])
    272         if self.skipPageChange:
    273 #            self.skipPageChange = False
    274 #            if tabLabel in self.treeItem:
    275 #                del self.treeItem[tabLabel]
    276             return
    277         page = self.panelList[self.nb.GetSelection()]   #GetCurrentPage() not in wx 2.7
    278         if tabLabel in self.treeItem:
    279             treeItems, tabname = self.treeItem[tabLabel]
    280             pid = self.G2frame.root
    281             try:
    282                 for item in treeItems:
    283                     pid = G2gd.GetPatternTreeItemId(self.G2frame, pid, item)
    284                 wx.CallLater(100,self.InvokeTreeItem,pid)
    285             except TypeError:
    286                 pass
    287         else:
    288             pass
    289 #            print 'OnPageChanged: not found:',tabLabel         #comment out for now
    290355           
    291356    def InvokeTreeItem(self,pid):
     
    485550    if not Title:
    486551        Title = Name
    487     try:
    488         plotNum = G2frame.G2plotNB.plotList.index('Structure Factors')
    489         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     552    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Structure Factors','mpl')
     553    if not new:
    490554        if not newPlot:
    491             Plot = Page.figure.gca()          #get previous powder plot & get limits
    492             xylim = Plot.get_xlim(),Plot.get_ylim()
    493         Page.figure.clf()
    494         Plot = Page.figure.gca()          #get a fresh plot after clf()
    495         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    496     except ValueError:
    497         Plot = G2frame.G2plotNB.addMpl('Structure Factors').gca()
    498         plotNum = G2frame.G2plotNB.plotList.index('Structure Factors')
    499         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     555            xylim = lim
     556    else:
    500557        Page.canvas.mpl_connect('button_press_event', OnSCPress)
    501558        Page.canvas.mpl_connect('motion_notify_event', OnSCMotion)
     
    509566        if 'HKLF' in Name:
    510567            Page.Choice += ('w: select |DFsq|/sig','1: select |DFsq|>sig','3: select |DFsq|>3sig',)
    511     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    512568    Plot.set_aspect(aspect='equal')
    513569   
     
    10961152
    10971153    # PlotStructure execution starts here (N.B. initialization above)
    1098     try:
    1099         plotNum = G2frame.G2plotNB.plotList.index('3D Structure Factors')
    1100         Page = G2frame.G2plotNB.nb.GetPage(plotNum)       
    1101         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    1102     except ValueError:
    1103         Plot = G2frame.G2plotNB.addOgl('3D Structure Factors')
    1104         plotNum = G2frame.G2plotNB.plotList.index('3D Structure Factors')
    1105         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     1154    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('3D Structure Factors','ogl')
     1155    if new:
    11061156        Page.views = False
    11071157        view = False
    11081158        altDown = False
    11091159    Font = Page.GetFont()
    1110     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    11111160    Page.Choice = None
    11121161    choice = [' save as/key:','jpeg','tiff','bmp','h: view down h','k: view down k','l: view down l',
     
    11381187##### PlotPatterns
    11391188################################################################################
    1140            
     1189def ReplotPattern(G2frame,newPlot,plotType,PatternName=None,PickName=None):
     1190    '''This does the same as PlotPatterns except that it expects the information
     1191    to be plotted (pattern name, item picked in tree + eventually the reflection list)
     1192    to be passed as names rather than references to wx tree items, defined as class entries
     1193    '''
     1194    if PatternName:
     1195        G2frame.PatternId = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, PatternName)
     1196    if PickName == PatternName:
     1197        G2frame.PickId = G2frame.PatternId
     1198    elif PickName:
     1199        G2frame.PickId = G2gd.GetPatternTreeItemId(G2frame, G2frame.PatternId, PickName)
     1200    # for now I am not sure how to regenerate G2frame.HKL
     1201    G2frame.HKL = [] # TODO
     1202    PlotPatterns(G2frame,newPlot,plotType)
     1203
    11411204def PlotPatterns(G2frame,newPlot=False,plotType='PWDR'):
    11421205    '''Powder pattern plotting package - displays single or multiple powder patterns as intensity vs
    11431206    2-theta, q or TOF. Can display multiple patterns as "waterfall plots" or contour plots. Log I
    11441207    plotting available.
     1208
     1209    Note that plotting information will be found in:
     1210       G2frame.PatternId (contains the tree item for the current histogram)
     1211       G2frame.PickId (contains the actual selected tree item (can be child of histogram)
     1212       G2frame.HKL (contains a reflection list -- when used unclear)
    11451213    '''
    11461214    global exclLines
     
    11491217    global Pattern
    11501218    plottype = plotType
    1151        
     1219   
    11521220    if not G2frame.PatternId:
    11531221        return
     
    16051673
    16061674    # beginning PlotPatterns execution
    1607     try:
    1608         plotNum = G2frame.G2plotNB.plotList.index('Powder Patterns')
    1609         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    1610         Plot = Page.figure.gca()          #get previous powder plot & get limits
    1611         G2frame.xylim = Plot.get_xlim(),Plot.get_ylim()
    1612         Page.figure.clf()
    1613         Plot = Page.figure.gca()          #get a fresh plot after clf()
    1614         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    1615     except (ValueError,AttributeError):
     1675    new,plotNum,Page,Plot,limits = G2frame.G2plotNB.FindPlotTab('Powder Patterns','mpl')
     1676    if not new:
     1677        G2frame.xylim = limits
     1678    else:
    16161679        if plottype == 'SASD':
    16171680            G2frame.logPlot = True
     
    16191682        newPlot = True
    16201683        G2frame.Cmax = 1.0
    1621         Plot = G2frame.G2plotNB.addMpl('Powder Patterns').gca()
    1622         plotNum = G2frame.G2plotNB.plotList.index('Powder Patterns')
    1623         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    16241684        Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress)
    16251685        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
     
    16271687        Page.canvas.mpl_connect('button_release_event', OnRelease)
    16281688        Page.canvas.mpl_connect('button_press_event',OnPress)
    1629 #    if plottype == 'PWDR':  # avoids a very nasty clash with KILL_FOCUS in SASD TextCtrl?
    1630 #        Page.SetFocus()
    1631 #    G2frame.G2plotNB.skipPageChange = True      #to keep Stress/Strain data tab visible
     1689    # save information needed to reload from tree and redraw
     1690    kwargs={'PatternName':G2frame.PatternTree.GetItemText(G2frame.PatternId)}
     1691    if G2frame.PickId:
     1692        kwargs['PickName'] = G2frame.PatternTree.GetItemText(G2frame.PickId)
     1693    #G2frame.G2plotNB.RegisterRedrawRoutine('Powder Patterns',ReplotPattern,
     1694    G2frame.G2plotNB.RegisterRedrawRoutine(G2frame.G2plotNB.lastRaisedPlotTab,ReplotPattern,
     1695                                           (G2frame,newPlot,plotType),kwargs)
     1696    # now start plotting
    16321697    G2frame.G2plotNB.status.DestroyChildren()
    16331698    if G2frame.Contour:
     
    20672132################################################################################
    20682133           
    2069 def PlotDeltSig(G2frame,kind):
    2070     'needs a doc string'
    2071     try:
    2072         plotNum = G2frame.G2plotNB.plotList.index('Error analysis')
    2073         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    2074         Page.figure.clf()
    2075         Plot = Page.figure.gca()          #get a fresh plot after clf()
    2076         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    2077     except ValueError:
     2134def PlotDeltSig(G2frame,kind,PatternName=None):
     2135    'Produces normal probability plot for a powder or single crystal histogram'
     2136    if PatternName:
     2137        G2frame.PatternId = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, PatternName)
     2138    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Error analysis','mpl')
     2139    if new:
    20782140        newPlot = True
    20792141        G2frame.Cmax = 1.0
    2080         Plot = G2frame.G2plotNB.addMpl('Error analysis').gca()
    2081         plotNum = G2frame.G2plotNB.plotList.index('Error analysis')
    2082         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     2142    # save information needed to reload from tree and redraw
     2143    G2frame.G2plotNB.RegisterRedrawRoutine(G2frame.G2plotNB.lastRaisedPlotTab,
     2144                                           PlotDeltSig,(
     2145                                               G2frame,kind,
     2146                                               G2frame.PatternTree.GetItemText(G2frame.PatternId))
     2147                                           )
    20832148    Page.Choice = None
    20842149    PatternId = G2frame.PatternId
     
    21012166            if ref[6+im] > 0.:
    21022167                DS.append((ref[5+im]-ref[7+im])/ref[6+im])
    2103     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    21042168    G2frame.G2plotNB.status.DestroyChildren()
    21052169    DS.sort()
     
    22152279   
    22162280    xylim = []
    2217     try:
    2218         plotNum = G2frame.G2plotNB.plotList.index(type)
    2219         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     2281    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab(type,'mpl')
     2282    if not new:
    22202283        if not newPlot:
    2221             Plot = Page.figure.gca()          #get previous plot & get limits
    2222             xylim = Plot.get_xlim(),Plot.get_ylim()
    2223         Page.figure.clf()
    2224         Plot = Page.figure.gca()
    2225         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    2226     except ValueError:
     2284            xylim = lim
     2285    else:
    22272286        newPlot = True
    22282287        G2frame.Cmax = 1.0
    2229         Plot = G2frame.G2plotNB.addMpl(type).gca()
    2230         plotNum = G2frame.G2plotNB.plotList.index(type)
    2231         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    22322288        Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress)
    22332289        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
    22342290        Page.Offset = [0,0]
    22352291   
    2236     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    22372292    G2frame.G2plotNB.status.DestroyChildren()
    2238     G2frame.G2plotNB.skipPageChange = True      #to keep ISFG data tab visible
    22392293    if G2frame.Contour:
    22402294        Page.Choice = (' key press','d: lower contour max','u: raise contour max',
     
    23682422                Page.canvas.SetToolTipString('')
    23692423
     2424    xylim = []
    23702425    Title = 'Position calibration'
    2371     try:
    2372         plotNum = G2frame.G2plotNB.plotList.index(Title)
    2373         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     2426    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab(Title,'mpl')
     2427    if not new:
    23742428        if not newPlot:
    2375             Plot = Page.figure.gca()
    2376             xylim = Plot.get_xlim(),Plot.get_ylim()
    2377         Page.figure.clf()
    2378         Plot = Page.figure.gca()
    2379         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    2380     except ValueError:
     2429            xylim = lim
     2430    else:
    23812431        newPlot = True
    2382         Plot = G2frame.G2plotNB.addMpl(Title).gca()
    2383         plotNum = G2frame.G2plotNB.plotList.index(Title)
    2384         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    23852432        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
    23862433   
    23872434    Page.Choice = None
    2388     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    23892435    G2frame.G2plotNB.status.DestroyChildren()
    23902436    Plot.set_title(Title)
     
    24882534                G2frame.G2plotNB.status.SetStatusText('Select '+Title+' pattern first',1)
    24892535
    2490     try:
    2491         plotNum = G2frame.G2plotNB.plotList.index(Title)
    2492         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     2536    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab(Title,'mpl')
     2537    if not new:
    24932538        if not newPlot:
    2494             Plot = Page.figure.gca()
    2495             xylim = Plot.get_xlim(),Plot.get_ylim()
    2496         Page.figure.clf()
    2497         Plot = Page.figure.gca()
    2498         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    2499     except ValueError:
     2539            xylim = lim
     2540    else:
    25002541        newPlot = True
    2501         Plot = G2frame.G2plotNB.addMpl(Title).gca()
    2502         plotNum = G2frame.G2plotNB.plotList.index(Title)
    2503         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    25042542        Page.canvas.mpl_connect('key_press_event', OnKeyPress)
    25052543        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
     
    25112549    else:
    25122550        Page.Choice = None
    2513     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    2514     G2frame.G2plotNB.skipPageChange = True     
    25152551    G2frame.G2plotNB.status.DestroyChildren()
    25162552    Plot.set_title(Title)
     
    26272663                    G2frame.G2plotNB.status.SetStatusText('Select '+Title+' pattern first',1)
    26282664                   
    2629     try:
    2630         plotNum = G2frame.G2plotNB.plotList.index(Title)
    2631         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     2665    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab(Title,'mpl')
     2666    if not new:
    26322667        if not newPlot:
    2633             Plot = Page.figure.gca()
    2634             xylim = Plot.get_xlim(),Plot.get_ylim()
    2635         Page.figure.clf()
    2636         Plot = Page.figure.gca()
    2637         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    2638     except ValueError:
     2668            xylim = lim
     2669    else:
    26392670        newPlot = True
    2640         Plot = G2frame.G2plotNB.addMpl(Title).gca()
    2641         plotNum = G2frame.G2plotNB.plotList.index(Title)
    2642         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    26432671        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
    26442672        Page.canvas.mpl_connect('key_press_event', OnKeyPress)
     
    26462674    Page.Choice = (' key press','d: lower contour max','u: raise contour max','o: reset contour max',
    26472675        'i: interpolation method','s: color scheme')
    2648     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    26492676    Page.keyPress = OnKeyPress
    26502677    Page.SetFocus()
     
    26982725                G2frame.G2plotNB.status.SetStatusText('Select Strain pattern first',1)
    26992726
    2700     try:
    2701         plotNum = G2frame.G2plotNB.plotList.index('Strain')
    2702         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     2727    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Strain','mpl')
     2728    if not new:
    27032729        if not newPlot:
    2704             Plot = Page.figure.gca()
    2705             xylim = Plot.get_xlim(),Plot.get_ylim()
    2706         Page.figure.clf()
    2707         Plot = Page.figure.gca()
    2708         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    2709     except ValueError:
     2730            xylim = lim
     2731    else:
    27102732        newPlot = True
    2711         Plot = G2frame.G2plotNB.addMpl('Strain').gca()
    2712         plotNum = G2frame.G2plotNB.plotList.index('Strain')
    2713         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    27142733        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
    27152734   
    27162735    Page.Choice = None
    2717     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    2718     G2frame.G2plotNB.skipPageChange = True      #to keep Stress/Strain data tab visible
    27192736    G2frame.G2plotNB.status.DestroyChildren()
    27202737    Plot.set_title('Strain')
     
    27612778                G2frame.G2plotNB.status.SetStatusText('Select Strain pattern first',1)
    27622779
    2763     try:
    2764         plotNum = G2frame.G2plotNB.plotList.index('Size Distribution')
    2765         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    2766         Page.figure.clf()
    2767         Plot = Page.figure.gca()          #get a fresh plot after clf()
    2768         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    2769     except ValueError:
     2780    xylim = []
     2781    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Size Distribution','mpl')
     2782    if new:
    27702783        newPlot = True
    2771         Plot = G2frame.G2plotNB.addMpl('Size Distribution').gca()
    27722784        G2frame.G2plotNB.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED,OnPageChanged)
    2773         plotNum = G2frame.G2plotNB.plotList.index('Size Distribution')
    2774         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    27752785        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
    27762786    Page.Choice = None
    2777     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    27782787    PatternId = G2frame.PatternId
    27792788    data = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Models'))
     
    28182827                    Page.canvas.SetToolTipString('')
    28192828
    2820     try:
    2821         plotNum = G2frame.G2plotNB.plotList.index('Powder Lines')
    2822         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    2823         Page.figure.clf()
    2824         Plot = Page.figure.gca()
    2825         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    2826     except ValueError:
    2827         Plot = G2frame.G2plotNB.addMpl('Powder Lines').gca()
    2828         plotNum = G2frame.G2plotNB.plotList.index('Powder Lines')
    2829         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     2829    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Powder Lines','mpl')
     2830    if new:
    28302831        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
    2831        
    28322832    Page.Choice = None
    2833     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    28342833    Plot.set_title('Powder Pattern Lines')
    28352834    Plot.set_xlabel(r'$\mathsf{2\theta}$',fontsize=14)
     
    28532852################################################################################
    28542853           
    2855 def PlotPeakWidths(G2frame):
     2854def PlotPeakWidths(G2frame,PatternName=None):
    28562855    ''' Plotting of instrument broadening terms as function of 2-theta
    2857     Seen when "Instrument Parameters" chosen from powder pattern data tree
     2856    Seen when "Instrument Parameters" chosen from powder pattern data tree.
     2857    Parameter PatternName allows the PWDR to be referenced as a string rather than
     2858    a wx tree item, defined in G2frame.PatternId.
    28582859    '''
    28592860#    sig = lambda Th,U,V,W: 1.17741*math.sqrt(U*tand(Th)**2+V*tand(Th)+W)*math.pi/18000.
     
    28612862#    gamFW = lambda s,g: np.exp(np.log(s**5+2.69269*s**4*g+2.42843*s**3*g**2+4.47163*s**2*g**3+0.07842*s*g**4+g**5)/5.)
    28622863#    gamFW2 = lambda s,g: math.sqrt(s**2+(0.4654996*g)**2)+.5345004*g  #Ubaldo Bafile - private communication
     2864    if PatternName:
     2865        G2frame.PatternId = G2gd.GetPatternTreeItemId(G2frame, G2frame.root, PatternName)
    28632866    PatternId = G2frame.PatternId
    28642867    limitID = G2gd.GetPatternTreeItemId(G2frame,PatternId, 'Limits')
     
    28862889        return
    28872890    xylim = []
    2888     try:
    2889         plotNum = G2frame.G2plotNB.plotList.index('Peak Widths')
    2890         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    2891         Plot = Page.figure.gca()
     2891    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Peak Widths','mpl')
     2892    if not new:
    28922893        if not G2frame.G2plotNB.allowZoomReset: # save previous limits
    2893             xylim = Plot.get_xlim(),Plot.get_ylim()
    2894         Page.figure.clf()
    2895         Plot = Page.figure.gca()
    2896         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    2897     except ValueError:
    2898         Plot = G2frame.G2plotNB.addMpl('Peak Widths').gca()
    2899         plotNum = G2frame.G2plotNB.plotList.index('Peak Widths')
    2900         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     2894            xylim = lim
     2895    # save information needed to reload from tree and redraw
     2896    G2frame.G2plotNB.RegisterRedrawRoutine(G2frame.G2plotNB.lastRaisedPlotTab,
     2897            PlotPeakWidths,(G2frame,G2frame.PatternTree.GetItemText(G2frame.PatternId))
     2898            )
    29012899
    29022900    TreeItemText = G2frame.PatternTree.GetItemText(G2frame.PatternId)
    29032901    G2frame.G2plotNB.status.SetStatusText('histogram: '+TreeItemText,1)
    29042902    Page.Choice = None
    2905     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    2906    
    29072903    Page.canvas.SetToolTipString('')
    29082904    colors=['b','g','r','c','m','k']
     
    30943090    numPlots = len(useList)
    30953091
    3096     try:
    3097         plotNum = G2frame.G2plotNB.plotList.index(plotType)
    3098         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    3099         Page.figure.clf()
    3100         Plot = Page.figure.gca()
     3092    if plotType in ['Mustrain','Size']:
     3093        new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab(plotType,'3d')
     3094    else:
     3095        new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab(plotType,'mpl')
     3096    if not new:
    31013097        if not Page.IsShown():
    31023098            Page.Show()
    3103     except ValueError:
    3104         if plotType in ['Mustrain','Size']:
    3105             Plot = mp3d.Axes3D(G2frame.G2plotNB.add3D(plotType))
    3106         else:
    3107             Plot = G2frame.G2plotNB.addMpl(plotType).gca()               
    3108         plotNum = G2frame.G2plotNB.plotList.index(plotType)
    3109         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     3099    else:
    31103100        Page.canvas.mpl_connect('pick_event', OnPick)
    31113101        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
    31123102    Page.Choice = None
    3113     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    3114     G2frame.G2plotNB.skipPageChange = True
    31153103    G2frame.G2plotNB.status.SetStatusText('',1)
    31163104   
     
    33723360                    G2frame.G2plotNB.status.SetStatusText('phi =%9.3f, gam =%9.3f, MRD =%9.3f'%(r,p,pf),1)
    33733361
    3374     try:
    3375         plotNum = G2frame.G2plotNB.plotList.index('Texture')
    3376         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    3377         Page.figure.clf()
    3378         Plot = Page.figure.gca()
     3362    if '3D' in SHData['PlotType']:
     3363        new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Texture','3d')
     3364    else:
     3365        new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Texture','mpl')
     3366    if not new:
    33793367        if not Page.IsShown():
    33803368            Page.Show()
    3381         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    3382     except ValueError:
    3383         if '3D' in SHData['PlotType']:
    3384             Plot = mp3d.Axes3D(G2frame.G2plotNB.add3D('Texture'))
    3385         else:
    3386             Plot = G2frame.G2plotNB.addMpl('Texture').gca()               
    3387         plotNum = G2frame.G2plotNB.plotList.index('Texture')
    3388         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     3369    else:
    33893370        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
    3390 
    33913371    Page.Choice = None
    3392     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    3393     G2frame.G2plotNB.skipPageChange = True
    33943372    G2frame.G2plotNB.status.SetFields(['',''])   
    33953373    G2frame.G2plotNB.status.SetStatusWidths([150,-1])
     
    35293507        wx.CallAfter(ModulationPlot,G2frame,data,Atom,Ax,Off)
    35303508
    3531     try:
    3532         plotNum = G2frame.G2plotNB.plotList.index('Modulation')
    3533         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    3534         Page.figure.clf()
    3535         Plot = Page.figure.gca()
     3509    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Modulation','mpl')
     3510    if not new:
    35363511        if not Page.IsShown():
    35373512            Page.Show()
    3538         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    3539     except ValueError:
    3540         Plot = G2frame.G2plotNB.addMpl('Modulation').gca()
    3541         plotNum = G2frame.G2plotNB.plotList.index('Modulation')
    3542         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     3513    else:
    35433514        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
    35443515        Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress)
    3545    
    3546     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    35473516    G2frame.G2plotNB.status.DestroyChildren()
    35483517    General = data['General']
     
    36333602    newAtomDict = Data.get('newAtomDict',{})
    36343603    G2frame.G2plotNB.status.DestroyChildren()
    3635    
    36363604
    36373605    def OnPlotKeyPress(event):
     
    36703638                G2frame.G2plotNB.status.SetStatusText(msg,1)
    36713639               
    3672     try:
    3673         plotNum = G2frame.G2plotNB.plotList.index('Covariance')
    3674         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    3675         Page.figure.clf()
    3676         Plot = Page.figure.gca()
     3640    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Covariance','mpl')
     3641    if not new:
    36773642        if not Page.IsShown():
    36783643            Page.Show()
    3679         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    3680     except ValueError:
    3681         Plot = G2frame.G2plotNB.addMpl('Covariance').gca()
    3682         plotNum = G2frame.G2plotNB.plotList.index('Covariance')
    3683         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     3644    else:
    36843645        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
    36853646        Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress)
    36863647    Page.Choice = ['s: to change colors']
    36873648    Page.keyPress = OnPlotKeyPress
    3688     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    36893649    G2frame.G2plotNB.status.SetFields(['',''])
    36903650    G2frame.G2plotNB.status.SetStatusWidths([150,-1])   #need to reset field widths here   
     
    37413701            Page.canvas.SetToolTipString(msg)
    37423702
    3743     try:
    3744         plotNum = G2frame.G2plotNB.plotList.index('Torsion')
    3745         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    3746         Page.figure.clf()
    3747         Plot = Page.figure.gca()
     3703    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Torsion','mpl')
     3704    if not new:
    37483705        if not Page.IsShown():
    37493706            Page.Show()
    3750         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    3751     except ValueError:
    3752         Plot = G2frame.G2plotNB.addMpl('Torsion').gca()
    3753         plotNum = G2frame.G2plotNB.plotList.index('Torsion')
    3754         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     3707    else:
    37553708        Page.canvas.mpl_connect('pick_event', OnPick)
    37563709        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
    3757    
    3758     G2frame.G2plotNB.RaisePageNoRefresh(Page)
     3710
    37593711    G2frame.G2plotNB.status.SetStatusText('Use mouse LB to identify torsion atoms',1)
    37603712    Plot.plot(X,torsion,'b+')
     
    38253777            Page.canvas.SetToolTipString(msg)
    38263778           
    3827     try:
    3828         plotNum = G2frame.G2plotNB.plotList.index('Ramachandran')
    3829         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    3830         Page.figure.clf()
    3831         Plot = Page.figure.gca()
     3779    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Ramachandran','mpl')
     3780    if not new:
    38323781        if not Page.IsShown():
    38333782            Page.Show()
    3834         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    3835     except ValueError:
    3836         Plot = G2frame.G2plotNB.addMpl('Ramachandran').gca()
    3837         plotNum = G2frame.G2plotNB.plotList.index('Ramachandran')
    3838         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     3783    else:
    38393784        Page.canvas.mpl_connect('pick_event', OnPick)
    38403785        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
     
    38433788    Page.Choice = ['s: to change colors']
    38443789    Page.keyPress = OnPlotKeyPress
    3845     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    38463790    G2frame.G2plotNB.status.SetStatusText('Use mouse LB to identify phi/psi atoms',1)
    38473791    acolor = mpl.cm.get_cmap(G2frame.RamaColor)
     
    39833927    else:
    39843928        label = 'Parametric fit #'+str(fitnum+1)
    3985     try:
    3986         plotNum = G2frame.G2plotNB.plotList.index(label)
    3987         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    3988         Page.figure.clf()
    3989         Plot = Page.figure.gca()
     3929    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab(label,'mpl')
     3930    if not new:
    39903931        if not Page.IsShown():
    39913932            Page.Show()
    3992     except ValueError:
    3993         Plot = G2frame.G2plotNB.addMpl(label).gca()
    3994         plotNum = G2frame.G2plotNB.plotList.index(label)
    3995         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     3933    else:
    39963934        Page.canvas.mpl_connect('key_press_event', OnKeyPress)
    39973935        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
     
    40033941       
    40043942    Draw()
    4005     G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    40063943               
    40073944################################################################################
     
    43734310        return
    43744311    xylim = []
    4375     try:
    4376         plotNum = G2frame.G2plotNB.plotList.index('2D Powder Image')
    4377         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     4312    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('2D Powder Image','mpl',newImage=newImage)
     4313    if not new:
    43784314        if not newPlot:
    4379             Plot = Page.figure.gca()          #get previous powder plot & get limits
    4380             xylim = Plot.get_xlim(),Plot.get_ylim()
    4381         if newImage:
    4382             Page.figure.clf()
    4383             Plot = Page.figure.gca()          #get a fresh plot after clf()
    4384     except ValueError:
    4385         Plot = G2frame.G2plotNB.addMpl('2D Powder Image').gca()
    4386         plotNum = G2frame.G2plotNB.plotList.index('2D Powder Image')
    4387         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     4315            xylim = lim
     4316    else:
    43884317        Page.canvas.mpl_connect('key_press_event', OnImPlotKeyPress)
    43894318        Page.canvas.mpl_connect('motion_notify_event', OnImMotion)
    43904319        Page.canvas.mpl_connect('pick_event', OnImPick)
    43914320        Page.canvas.mpl_connect('button_release_event', OnImRelease)
    4392         xylim = []
    43934321    Page.Choice = None
    4394     if not event:                       #event from GUI TextCtrl - don't want focus to change to plot!!!
    4395         G2frame.G2plotNB.RaisePageNoRefresh(Page)
    4396     G2frame.G2plotNB.skipPageChange = True
    43974322    Title = G2frame.PatternTree.GetItemText(G2frame.Image)[4:]
    43984323    G2frame.G2plotNB.status.DestroyChildren()
     
    46164541                'Detector 2-th =%9.3fdeg, azm = %7.2fdeg'%(tth,azm),1)
    46174542                               
    4618     try:
    4619         plotNum = G2frame.G2plotNB.plotList.index('2D Integration')
    4620         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     4543    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('2D Integration','mpl')
     4544    if not new:
    46214545        if not newPlot:
    4622             Plot = Page.figure.gca()          #get previous plot & get limits
    4623             xylim = Plot.get_xlim(),Plot.get_ylim()
    4624         Page.figure.clf()
    4625         Plot = Page.figure.gca()          #get a fresh plot after clf()
    4626 #        if not event:
    4627 #            G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    4628        
    4629     except ValueError:
    4630         Plot = G2frame.G2plotNB.addMpl('2D Integration').gca()
    4631         plotNum = G2frame.G2plotNB.plotList.index('2D Integration')
    4632         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     4546            xylim = lim
     4547    else:
    46334548        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
    46344549        Page.views = False
    46354550        view = False
    46364551    Page.Choice = None
    4637     if not event:
    4638         G2frame.G2plotNB.RaisePageNoRefresh(Page)
    46394552       
    46404553    Data = G2frame.PatternTree.GetItemPyData(
     
    46844597                'Detector 2-th =%9.3fdeg, azm = %7.2fdeg'%(tth,azm),1)
    46854598                               
    4686     try:
    4687         plotNum = G2frame.G2plotNB.plotList.index('2D Transformed Powder Image')
    4688         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     4599    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('2D Transformed Powder Image','mpl')
     4600    if not new:
    46894601        if not newPlot:
    4690             Plot = Page.figure.gca()          #get previous plot & get limits
    4691             xylim = Plot.get_xlim(),Plot.get_ylim()
    4692         Page.figure.clf()
    4693         Plot = Page.figure.gca()          #get a fresh plot after clf()
    4694         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    4695        
    4696     except ValueError:
    4697         Plot = G2frame.G2plotNB.addMpl('2D Transformed Powder Image').gca()
    4698         plotNum = G2frame.G2plotNB.plotList.index('2D Transformed Powder Image')
    4699         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     4602            xylim = lim
     4603    else:
    47004604        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
    47014605        Page.views = False
    47024606        view = False
    47034607    Page.Choice = None
    4704     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    4705        
    47064608    Data = G2frame.PatternTree.GetItemPyData(
    47074609        G2gd.GetPatternTreeItemId(G2frame,G2frame.Image, 'Image Controls'))
     
    58625764       
    58635765    # PlotStructure execution starts here (N.B. initialization above)
    5864     try:
    5865         plotNum = G2frame.G2plotNB.plotList.index(generalData['Name'])
    5866         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
    5867         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    5868     except ValueError:
    5869         Plot = G2frame.G2plotNB.addOgl(generalData['Name'])
    5870         plotNum = G2frame.G2plotNB.plotList.index(generalData['Name'])
    5871         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     5766    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab(generalData['Name'],'ogl')
     5767    if new:
    58725768        Page.views = False
    58735769        view = False
    58745770        altDown = False
    58755771    Font = Page.GetFont()
    5876     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    58775772    Page.Choice = None
    58785773    if mapData.get('Flip',False):
     
    61886083            G2frame.G2plotNB.status.SetStatusText('Drawing saved to: '+Fname,1)
    61896084
    6190     try:
    6191         plotNum = G2frame.G2plotNB.plotList.index('Rigid body')
    6192         Page = G2frame.G2plotNB.nb.GetPage(plotNum)       
    6193         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    6194     except ValueError:
    6195         Plot = G2frame.G2plotNB.addOgl('Rigid body')
    6196         plotNum = G2frame.G2plotNB.plotList.index('Rigid body')
    6197         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     6085    # PlotStructure execution starts here (N.B. initialization above)
     6086    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Rigid body','ogl')
     6087    if new:
    61986088        Page.views = False
    61996089        view = False
    62006090        altDown = False
    6201 #    GSASIIpath.IPyBreak()
    62026091    Page.name = rbData['RBname']
    6203     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    62046092    Page.Choice = None
    62056093    choice = [' save as:','jpeg','tiff','bmp',]
     
    62916179        Bonds = FindBonds(AtTypes,XYZ)
    62926180                       
    6293     cell = Layers['Cell'][1:7]
    6294     Amat,Bmat = G2lat.cell2AB(cell)         #Amat - crystal to cartesian, Bmat - inverse
    6295     A4mat = np.concatenate((np.concatenate((Amat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0)
    6296     B4mat = np.concatenate((np.concatenate((Bmat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0)
    6297     Trans = Layers['Transitions']
    6298     Wt = np.array([255,255,255])
    6299     Rd = np.array([255,0,0])
    6300     Gr = np.array([0,255,0])
    6301     Bl = np.array([0,0,255])
    6302     Bc = np.array([0,0,0])
    6303     uBox = np.array([[0,0,0],[1,0,0],[1,1,0],[0,1,0],[0,0,1],[1,0,1],[1,1,1],[0,1,1]])
    6304     uEdges = np.array([
    6305         [uBox[0],uBox[1]],[uBox[0],uBox[3]],[uBox[0],uBox[4]],[uBox[1],uBox[2]],
    6306         [uBox[2],uBox[3]],[uBox[1],uBox[5]],[uBox[2],uBox[6]],[uBox[3],uBox[7]],
    6307         [uBox[4],uBox[5]],[uBox[5],uBox[6]],[uBox[6],uBox[7]],[uBox[7],uBox[4]]])
    6308     uColors = [Rd,Gr,Bl,Wt-Bc, Wt-Bc,Wt-Bc,Wt-Bc,Wt-Bc, Wt-Bc,Wt-Bc,Wt-Bc,Wt-Bc]
    6309     uEdges[2][1][2] = len(laySeq)
    6310     AtInfo = Layers['AtInfo']
    6311     Names = [layer['Name'] for layer in Layers['Layers']]
    6312     getAtoms()
    6313    
    63146181    def OnKeyBox(event):
    63156182        mode = cb.GetValue()
     
    66066473        Draw('size')
    66076474       
    6608     try:
    6609         plotNum = G2frame.G2plotNB.plotList.index('Layer')
    6610         Page = G2frame.G2plotNB.nb.GetPage(plotNum)       
    6611         G2frame.G2plotNB.SetSelectionNoRefresh(plotNum) # raises plot tab
    6612     except ValueError:
    6613         Plot = G2frame.G2plotNB.addOgl('Layer')
    6614         plotNum = G2frame.G2plotNB.plotList.index('Layer')
    6615         Page = G2frame.G2plotNB.nb.GetPage(plotNum)
     6475    # PlotLayers execution starts here
     6476    cell = Layers['Cell'][1:7]
     6477    Amat,Bmat = G2lat.cell2AB(cell)         #Amat - crystal to cartesian, Bmat - inverse
     6478    A4mat = np.concatenate((np.concatenate((Amat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0)
     6479    B4mat = np.concatenate((np.concatenate((Bmat,[[0],[0],[0]]),axis=1),[[0,0,0,1],]),axis=0)
     6480    Trans = Layers['Transitions']
     6481    Wt = np.array([255,255,255])
     6482    Rd = np.array([255,0,0])
     6483    Gr = np.array([0,255,0])
     6484    Bl = np.array([0,0,255])
     6485    Bc = np.array([0,0,0])
     6486    uBox = np.array([[0,0,0],[1,0,0],[1,1,0],[0,1,0],[0,0,1],[1,0,1],[1,1,1],[0,1,1]])
     6487    uEdges = np.array([
     6488        [uBox[0],uBox[1]],[uBox[0],uBox[3]],[uBox[0],uBox[4]],[uBox[1],uBox[2]],
     6489        [uBox[2],uBox[3]],[uBox[1],uBox[5]],[uBox[2],uBox[6]],[uBox[3],uBox[7]],
     6490        [uBox[4],uBox[5]],[uBox[5],uBox[6]],[uBox[6],uBox[7]],[uBox[7],uBox[4]]])
     6491    uColors = [Rd,Gr,Bl,Wt-Bc, Wt-Bc,Wt-Bc,Wt-Bc,Wt-Bc, Wt-Bc,Wt-Bc,Wt-Bc,Wt-Bc]
     6492    uEdges[2][1][2] = len(laySeq)
     6493    AtInfo = Layers['AtInfo']
     6494    Names = [layer['Name'] for layer in Layers['Layers']]
     6495    getAtoms()
     6496   
     6497    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Layer','ogl')
     6498    if new:
    66166499        Page.views = False
    66176500        Page.labels = False
     
    66236506        choice += ['F - toggle fade','X/shift-X move Dx','Y/shift-Y move Dy','Z/shift-Z move Dz']
    66246507    Page.keyPress = OnPlotKeyPress
    6625     G2frame.G2plotNB.RaisePageNoRefresh(Page)
    66266508    Font = Page.GetFont()
    66276509    cb = wx.ComboBox(G2frame.G2plotNB.status,style=wx.CB_DROPDOWN|wx.CB_READONLY,choices=choice)
  • trunk/docs/source/index.rst

    r2087 r2479  
    3636
    3737Two packages are used by some parts of the code, but are not required:
     38
    3839* PIL (http://www.pythonware.com/products/pil/) or Pillow (https://pillow.readthedocs.org). This is used to save
    3940  and read certain types of images.
Note: See TracChangeset for help on using the changeset viewer.