Changeset 3576 for trunk/GSASIIplot.py
- Timestamp:
- Aug 27, 2018 5:01:06 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/GSASIIplot.py ¶
r3571 r3576 4343 4343 ypos = event.ydata 4344 4344 G2frame.G2plotNB.status.SetStatusText('q =%.3f%s %sq/q =%.4f'%(xpos,Angstr+Pwrm1,GkDelta,ypos),1) 4345 4345 4346 4346 if PatternName: 4347 4347 G2frame.PatternId = G2gd.GetGPXtreeItemId(G2frame, G2frame.root, PatternName) … … 4438 4438 Plot.plot(X,Z,'+',color='g',label='L peak') 4439 4439 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) 4441 4442 Page.canvas.draw() 4442 4443 else: #'T'OF … … 8711 8712 ''' 8712 8713 import NIST_profile as FP 8713 def clearHighlight(event):8714 l,lm,lms = Page.timer.lineinfo8715 l.set_marker(lm)8716 l.set_markersize(lms)8717 Page.canvas.draw()8718 Page.timer = None8719 8720 def onPick(event):8721 '''When a line in the legend is selected, find the matching line8722 in the plot and then highlight it by adding/enlarging markers.8723 Set up a timer to make a reset after 2.5 seconds8724 '''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 return8728 if Page.timer: # clear previous highlight8729 Page.timer.Stop()8730 clearHighlight(None)8731 return # if this is removed, the selected item is automatically highlighted8732 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 item8739 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 break8746 else:8747 print('Warning: artist matching ',lbl,' not found')8748 8749 8714 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 = None8753 8715 Page.SetToolTipString('') 8754 8716 cntr = NISTpk.twotheta_window_center_deg … … 8758 8720 refColors=['b','r','c','g','m','k'] 8759 8721 ttmin = ttmax = 0 8722 #GSASIIpath.IPyBreak() 8760 8723 for i,conv in enumerate(NISTpk.convolvers): 8724 if 'smoother' in conv: continue 8761 8725 f = NISTpk.convolver_funcs[conv]() 8762 8726 if f is None: continue … … 8771 8735 Plot.plot(ttArr,FFT,color,label=conv[5:]) 8772 8736 legend = Plot.legend(loc='best') 8773 for line in legend.get_lines(): 8774 line.set_picker(4) 8737 SetupLegendPick(legend,new) 8775 8738 Page.toolbar.push_current() 8776 8739 Plot.set_xlim((ttmin,ttmax)) … … 8778 8741 Page.toolbar.draw() 8779 8742 Page.canvas.draw() 8743 8744 def 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 8755 def 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.