Changeset 3576 for trunk/GSASIIplot.py


Ignore:
Timestamp:
Aug 27, 2018 5:01:06 PM (7 years ago)
Author:
toby
Message:

improve active legend code; FPA: add oversampling & remove smoother from plot

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/GSASIIplot.py

    r3571 r3576  
    43434343            ypos = event.ydata
    43444344            G2frame.G2plotNB.status.SetStatusText('q =%.3f%s %sq/q =%.4f'%(xpos,Angstr+Pwrm1,GkDelta,ypos),1)                   
    4345 
     4345           
    43464346    if PatternName:
    43474347        G2frame.PatternId = G2gd.GetGPXtreeItemId(G2frame, G2frame.root, PatternName)
     
    44384438            Plot.plot(X,Z,'+',color='g',label='L peak')
    44394439            Plot.plot(X,W,'+',color='b',label='G+L peak')
    4440         Plot.legend(loc='best')
     4440        legend = Plot.legend(loc='best')
     4441        SetupLegendPick(legend,new)
    44414442        Page.canvas.draw()
    44424443    else:   #'T'OF
     
    87118712    '''
    87128713    import NIST_profile as FP
    8713     def clearHighlight(event):
    8714         l,lm,lms = Page.timer.lineinfo
    8715         l.set_marker(lm)
    8716         l.set_markersize(lms)
    8717         Page.canvas.draw()
    8718         Page.timer = None
    8719        
    8720     def onPick(event):
    8721         '''When a line in the legend is selected, find the matching line
    8722         in the plot and then highlight it by adding/enlarging markers.
    8723         Set up a timer to make a reset after 2.5 seconds
    8724         '''
    8725         plot = event.artist.get_figure().get_axes()[0]
    8726         if event.artist not in plot.get_legend().get_lines():  # is this an item in the legend?
    8727             return
    8728         if Page.timer: # clear previous highlight
    8729             Page.timer.Stop()
    8730             clearHighlight(None)
    8731             return   # if this is removed, the selected item is automatically highlighted
    8732         lbl = event.artist.get_label()
    8733         for l in plot.get_lines():
    8734             if lbl == l.get_label():
    8735                 Page.timer = wx.Timer()
    8736                 Page.timer.Bind(wx.EVT_TIMER, clearHighlight)
    8737                 Page.timer.lineinfo = (l,l.get_marker(),l.get_markersize())
    8738                 # highlight the selected item
    8739                 if l.get_marker() == 'None':
    8740                     l.set_marker('o')
    8741                 else:
    8742                     l.set_markersize(2*l.get_markersize())
    8743                 Page.canvas.draw()
    8744                 Page.timer.Start(5000,oneShot=True)
    8745                 break
    8746         else:
    8747             print('Warning: artist matching ',lbl,' not found')
    8748                    
    87498714    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('FPA convolutors','mpl')
    8750     if new:
    8751         Page.canvas.mpl_connect('pick_event',onPick)
    8752     Page.timer = None
    87538715    Page.SetToolTipString('')
    87548716    cntr = NISTpk.twotheta_window_center_deg
     
    87588720    refColors=['b','r','c','g','m','k']
    87598721    ttmin = ttmax = 0
     8722    #GSASIIpath.IPyBreak()
    87608723    for i,conv in enumerate(NISTpk.convolvers):
     8724        if 'smoother' in conv: continue
    87618725        f = NISTpk.convolver_funcs[conv]()
    87628726        if f is None: continue
     
    87718735        Plot.plot(ttArr,FFT,color,label=conv[5:])
    87728736    legend = Plot.legend(loc='best')
    8773     for line in legend.get_lines():
    8774         line.set_picker(4)
     8737    SetupLegendPick(legend,new)
    87758738    Page.toolbar.push_current()
    87768739    Plot.set_xlim((ttmin,ttmax))
     
    87788741    Page.toolbar.draw()
    87798742    Page.canvas.draw()
     8743
     8744def SetupLegendPick(legend,new,delay=5):
     8745    legend.delay = delay*1000 # Hold time in ms for clear; 0 == forever
     8746    for line in legend.get_lines():
     8747        line.set_picker(4)
     8748        # bug: legend items with single markers don't seem to respond to a "pick"
     8749    #GSASIIpath.IPyBreak()
     8750    for txt in legend.get_texts():
     8751        txt.set_picker(4)
     8752    if new:
     8753        legend.figure.canvas.mpl_connect('pick_event',onLegendPick)
     8754       
     8755def onLegendPick(event):
     8756    '''When a line in the legend is selected, find the matching line
     8757    in the plot and then highlight it by adding/enlarging markers.
     8758    Set up a timer to make a reset after delay selected in SetupLegendPick
     8759    '''
     8760    def clearHighlight(event):
     8761        if not canvas.timer: return
     8762        l,lm,lms,lmw = canvas.timer.lineinfo
     8763        l.set_marker(lm)
     8764        l.set_markersize(lms)
     8765        l.set_markeredgewidth(lmw)
     8766        canvas.draw()
     8767        canvas.timer = None
     8768    canvas = event.artist.get_figure().canvas
     8769    if not hasattr(canvas,'timer'): canvas.timer = None
     8770    plot = event.artist.get_figure().get_axes()[0]
     8771    if hasattr(plot.get_legend(),'delay'):
     8772        delay = plot.get_legend().delay
     8773    if canvas.timer: # clear previous highlight
     8774        if delay > 0: canvas.timer.Stop()
     8775        clearHighlight(None)
     8776        #if delay <= 0: return   # use this in place of return
     8777        # so that the next selected item is automatically highlighted (except when delay is 0)
     8778        return
     8779    if event.artist in plot.get_legend().get_lines():  # is this an artist item in the legend?
     8780        lbl = event.artist.get_label()
     8781    elif event.artist in plot.get_legend().get_texts():  # is this a text item in the legend?
     8782        lbl = event.artist.get_text()
     8783    else:
     8784        #GSASIIpath.IPyBreak()
     8785        return
     8786   
     8787    for l in plot.get_lines():
     8788        if lbl == l.get_label():
     8789            canvas.timer = wx.Timer()
     8790            canvas.timer.Bind(wx.EVT_TIMER, clearHighlight)
     8791            #GSASIIpath.IPyBreak()
     8792            canvas.timer.lineinfo = (l,l.get_marker(),l.get_markersize(),l.get_markeredgewidth())
     8793            # highlight the selected item
     8794            if l.get_marker() == 'None':
     8795                l.set_marker('o')
     8796            else:
     8797                l.set_markersize(2*l.get_markersize())
     8798                l.set_markeredgewidth(2*l.get_markeredgewidth())
     8799            canvas.draw()
     8800            if delay > 0:
     8801                canvas.timer.Start(delay,oneShot=True)
     8802            break
     8803    else:
     8804            print('Warning: artist matching ',lbl,' not found')
     8805   
Note: See TracChangeset for help on using the changeset viewer.