Changeset 3913 for trunk/GSASIIplot.py
- Timestamp:
- Apr 21, 2019 10:05:23 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIplot.py
r3909 r3913 1744 1744 ##### PlotPatterns 1745 1745 ################################################################################ 1746 def SequentialPlotPattern(G2frame,refdata,histogram):1747 '''This is passed into :func:`GSASIIstrMain.SeqRefine` where it is used to1748 provide a plot of the current powder histogram just after a refinement. It1749 takes the old refinement information (Rfactors, curve locations, etc.) and1750 combines it with the refinement results in refdata and passes that to1751 :func:`PlotPatterns`1752 '''1753 if not histogram.startswith('PWDR'): return1754 pickId = G2frame.PickId1755 G2frame.PickId = G2frame.PatternId = G2gd.GetGPXtreeItemId(G2frame, G2frame.root, histogram)1756 treedata = G2frame.GPXtree.GetItemPyData(G2frame.PatternId)1757 PlotPatterns(G2frame,newPlot=True,plotType='PWDR',data=[treedata[0],refdata])1758 wx.Yield() # force a plot update (needed on Windows?)1759 G2frame.PickId = pickId1760 1761 1746 def ReplotPattern(G2frame,newPlot,plotType,PatternName=None,PickName=None): 1762 1747 '''This does the same as PlotPatterns except that it expects the information … … 1777 1762 1778 1763 def PlotPatterns(G2frame,newPlot=False,plotType='PWDR',data=None, 1779 extraKeys=[] ):1764 extraKeys=[],refineMode=False): 1780 1765 '''Powder pattern plotting package - displays single or multiple powder patterns as intensity vs 1781 1766 2-theta, q or TOF. Can display multiple patterns as "waterfall plots" or contour plots. Log I … … 2594 2579 else: 2595 2580 Plot.set_ylim(CurLims['ylims']) 2581 Page.toolbar.push_current() 2596 2582 Plot.figure.canvas.draw() 2597 2583 #GSASIIpath.IPyBreak() 2598 2584 2599 2585 def onPlotFormat(event): 2586 '''Change the appearance of the current plot''' 2600 2587 changePlotSettings(G2frame,Plot) 2588 2589 def refPlotUpdate(Histograms,cycle=None,restore=False): 2590 '''called to update an existing plot during a Rietveld fit 2591 ''' 2592 if restore: 2593 (G2frame.SinglePlot,G2frame.Contour,G2frame.Weight, 2594 G2frame.plusPlot,G2frame.SubBack,Page.plotStyle['logPlot']) = savedSettings 2595 return 2596 2597 if plottingItem not in Histograms: 2598 histoList = [i for i in Histograms.keys() if i.startswith('PWDR ')] 2599 if len(histoList) == 0: 2600 print('Skipping plot, no PWDR item found!') 2601 return 2602 plotItem = histoList[0] 2603 else: 2604 plotItem = plottingItem 2605 xye = np.array(ma.getdata(Histograms[plotItem]['Data'])) # strips mask 2606 xye0 = Histograms[plotItem]['Data'][0] 2607 if Page.plotStyle['qPlot']: 2608 X = 2.*np.pi/G2lat.Pos2dsp(Parms,xye0) 2609 Ibeg = np.searchsorted(X,2.*np.pi/G2lat.Pos2dsp(Parms,limits[1][0])) 2610 Ifin = np.searchsorted(X,2.*np.pi/G2lat.Pos2dsp(Parms,limits[1][1])) 2611 elif Page.plotStyle['dPlot']: 2612 X = G2lat.Pos2dsp(Parms,xye0) 2613 Ibeg = np.searchsorted(X,G2lat.Pos2dsp(Parms,limits[1][1])) 2614 Ifin = np.searchsorted(X,G2lat.Pos2dsp(Parms,limits[1][0])) 2615 else: 2616 X = copy.deepcopy(xye0) 2617 Ibeg = np.searchsorted(X,limits[1][0]) 2618 Ifin = np.searchsorted(X,limits[1][1]) 2619 if Page.plotStyle['sqrtPlot']: 2620 olderr = np.seterr(invalid='ignore') #get around sqrt(-ve) error 2621 Y = np.where(xye[1]>=0.,np.sqrt(xye[1]),-np.sqrt(-xye[1])) 2622 Z = np.where(xye[3]>=0.,np.sqrt(xye[3]),-np.sqrt(-xye[3])) 2623 W = np.where(xye[4]>=0.,np.sqrt(xye[4]),-np.sqrt(-xye[4])) 2624 #D = np.where(xye[5],(Y-Z),0.)-Page.plotStyle['delOffset'] 2625 np.seterr(invalid=olderr['invalid']) 2626 else: 2627 Y = copy.copy(xye[1]) 2628 Z = copy.copy(xye[3]) 2629 W = copy.copy(xye[4]) 2630 #D = xye[5]-Page.plotStyle['delOffset'] #powder background 2631 DZ = (xye[1]-xye[3])*np.sqrt(xye[2]) 2632 DifLine[0].set_xdata(X[Ibeg:Ifin]) 2633 DifLine[0].set_ydata(DZ[Ibeg:Ifin]) 2634 Plot1.set_ylim((min(DZ[Ibeg:Ifin]),max(DZ[Ibeg:Ifin]))) 2635 CalcLine[0].set_xdata(X) 2636 ObsLine[0].set_xdata(X) 2637 BackLine[0].set_xdata(X) 2638 CalcLine[0].set_ydata(Z) 2639 ObsLine[0].set_ydata(Y) 2640 BackLine[0].set_ydata(W) 2641 if cycle: 2642 Title = '{} cycle #{}'.format(plotItem,cycle) 2643 else: 2644 Title = plotItem 2645 if Page.plotStyle['sqrtPlot']: 2646 Plot.set_title(r'$\sqrt{I}$ for '+Title) 2647 else: 2648 Plot.set_title(Title) 2649 Page.canvas.draw() 2650 2601 2651 #===================================================================================== 2602 2652 # beginning PlotPatterns execution … … 2635 2685 G2frame.UseLimits = {'xlims':[False,False],'ylims':[False,False], 2636 2686 'dylims':[False,False]} 2687 #===================================================================================== 2688 # code to setup for plotting Rietveld results. Turns off multiplot, 2689 # sqrtplot, turn on + and weight plot, but sqrtPlot qPlot and dPlot are not changed. 2690 # Magnification regions are ignored. 2691 # the last-plotted histogram (from G2frame.PatternId) is used for this plotting 2692 # (except in seq. fitting) 2693 # Returns a pointer to refPlotUpdate, which is used to update the plot when this 2694 # returns 2695 if refineMode: 2696 plottingItem = G2frame.GPXtree.GetItemText(G2frame.PatternId) 2697 # save settings to be restored after refinement with repPlotUpdate({},restore=True) 2698 savedSettings = (G2frame.SinglePlot,G2frame.Contour,G2frame.Weight, 2699 G2frame.plusPlot,G2frame.SubBack,Page.plotStyle['logPlot']) 2700 G2frame.SinglePlot = True 2701 G2frame.Contour = False 2702 G2frame.Weight = True 2703 G2frame.plusPlot = True 2704 G2frame.SubBack = False 2705 Page.plotStyle['logPlot'] = False 2706 #===================================================================================== 2637 2707 if not new: 2638 2708 G2frame.xylim = limits … … 2907 2977 if 'PWDR' in plottype and G2frame.SinglePlot and not ( 2908 2978 Page.plotStyle['logPlot'] or Page.plotStyle['sqrtPlot'] or G2frame.Contour): 2909 magLineList = data[0].get('Magnification',[]) 2979 if not refineMode: 2980 magLineList = data[0].get('Magnification',[]) 2910 2981 if ('C' in ParmList[0]['Type'][0] and Page.plotStyle['dPlot']) or \ 2911 2982 ('T' in ParmList[0]['Type'][0] and Page.plotStyle['qPlot']): # reversed regions relative to data order … … 3054 3125 else: 3055 3126 Plot.set_ylim(bottom=np.min(np.trim_zeros(YB))/2.,top=np.max(Y)*2.) 3127 # Matplotlib artist lists used for refPlotUpdate 3128 ObsLine = None 3129 CalcLine = None 3130 BackLine = None 3131 DifLine = None 3056 3132 if G2frame.Weight: 3057 3133 Plot1.set_yscale("linear") … … 3095 3171 if G2frame.SubBack: 3096 3172 if 'PWDR' in plottype: 3097 Plot.plot(Xum,Y-W,colors[0]+pP,picker=False,clip_on=Clip_on,label='_obs') #Io-Ib3098 Plot.plot(X,Z-W,colors[1],picker=False,label='_calc') #Ic-Ib3173 ObsLine = Plot.plot(Xum,Y-W,colors[0]+pP,picker=False,clip_on=Clip_on,label='_obs') #Io-Ib 3174 CalcLine = Plot.plot(X,Z-W,colors[1],picker=False,label='_calc') #Ic-Ib 3099 3175 else: 3100 3176 Plot.plot(X,YB,colors[0]+pP,picker=3.,clip_on=Clip_on,label='_obs') … … 3103 3179 if 'PWDR' in plottype: 3104 3180 ObsLine = Plot.plot(Xum,Y,colors[0]+pP,picker=3.,clip_on=Clip_on,label='_obs') #Io 3105 Plot.plot(X,Z,colors[1],picker=False,label='_calc') #Ic3181 CalcLine = Plot.plot(X,Z,colors[1],picker=False,label='_calc') #Ic 3106 3182 else: 3107 3183 Plot.plot(X,YB,colors[0]+pP,picker=3.,clip_on=Clip_on,label='_obs') 3108 3184 Plot.plot(X,ZB,colors[1],picker=False,label='_calc') 3109 3185 if 'PWDR' in plottype and (G2frame.SinglePlot or G2frame.plusPlot): 3110 Plot.plot(X,W,colors[2],picker=False,label='_bkg') #Ib3186 BackLine = Plot.plot(X,W,colors[2],picker=False,label='_bkg') #Ib 3111 3187 if not G2frame.Weight: DifLine = Plot.plot(X,D,colors[3],picker=1.,label='_diff') #Io-Ic 3112 3188 Plot.axhline(0.,color='k',label='_zero') … … 3187 3263 Plot.axvline(hkl[-2],color=clr,dashes=(5,5)) 3188 3264 elif G2frame.GPXtree.GetItemText(PickId) in ['Reflection Lists'] or \ 3189 'PWDR' in G2frame.GPXtree.GetItemText(PickId) :3265 'PWDR' in G2frame.GPXtree.GetItemText(PickId) or refineMode: 3190 3266 Phases = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,PatternId,'Reflection Lists')) 3191 3267 l = GSASIIpath.GetConfigValue('Tick_length',8.0) … … 3281 3357 if DifLine[0]: 3282 3358 G2frame.dataWindow.moveDiffCurve.Enable(True) 3359 if refineMode: return refPlotUpdate 3283 3360 3284 3361 def PublishRietveldPlot(G2frame,Pattern,Plot,Page):
Note: See TracChangeset
for help on using the changeset viewer.