Changeset 3320 for trunk/GSASIIplot.py


Ignore:
Timestamp:
Mar 23, 2018 1:41:13 PM (5 years ago)
Author:
vondreele
Message:

implement new delt/sig subplot for PWDR & SASD plots - nvoked with 'w' key
make new MagStructureFactor2 routine - removed magnetism stuff from StructureFactor2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIplot.py

    r3316 r3320  
    425425            new = False
    426426            plotNum,Page = self.GetTabIndex(label)
    427             if Type == 'mpl' or Type == '3d':         
     427            if Type == 'mpl' or Type == '3d':
     428                Axes = Page.figure.get_axes()
    428429                Plot = Page.figure.gca()          #get previous plot
    429                 limits = Plot.get_xlim(),Plot.get_ylim() # save previous limits
    430 #                print 'Plot limits:',limits
     430                limits = [Plot.get_xlim(),Plot.get_ylim()] # save previous limits
     431                if len(Axes)>1:
     432                    limits[1] = Axes[1].get_ylim()
     433#                    print('Axes[1]',Axes[1].get_ylim())
     434#                print ('Plot limits:',limits,Axes)
    431435                if newImage:
    432436                    Page.figure.clf()
     
    581585            deleted = False
    582586        Toolbar.__init__(self,plotCanvas)
    583         G2path = os.path.split(os.path.abspath(__file__))[0]
     587#        G2path = os.path.split(os.path.abspath(__file__))[0]
    584588        self.updateActions = None # defines a call to be made as part of plot updates
    585589        self.plotCanvas = plotCanvas
     
    599603            fil = ''.join([i[0].lower() for i in direc.split()]+['arrow.ico'])
    600604            self.arrows[direc] = self.AddToolBarTool(sprfx+direc,prfx+direc,fil,self.OnArrow)
    601         G2path = os.path.split(os.path.abspath(__file__))[0]
     605#        G2path = os.path.split(os.path.abspath(__file__))[0]
    602606        if publish:
    603607            self.AddToolBarTool('Publish plot','Create publishable version of plot','publish.ico',publish)
     
    14941498            return
    14951499        newPlot = False
    1496         if event.key == 'w':
     1500        if event.key == 'w' and not G2frame.plotStyle['qPlot'] and not G2frame.plotStyle['dPlot']:  #can't do weight plots when x-axis is different
    14971501            G2frame.Weight = not G2frame.Weight
    14981502            if not G2frame.Weight and 'PWDR' in plottype:
     
    16011605                G2frame.plotStyle['qPlot'] = not G2frame.plotStyle['qPlot']
    16021606                if G2frame.plotStyle['qPlot']:
     1607                    G2frame.Weight = False
    16031608                    G2frame.Contour = False
    16041609                G2frame.plotStyle['dPlot'] = False
     
    16091614            if G2frame.plotStyle['dPlot']:
    16101615                G2frame.Contour = False               
     1616                G2frame.Weight = False
    16111617            G2frame.plotStyle['qPlot'] = False
    16121618            newPlot = True     
     
    21742180            if msg: msg += '\n'
    21752181            msg += " * only when the intensity scale is linear (not log or sqrt)"
     2182        if G2frame.Weight:
     2183            if msg: msg += '\n'
     2184            msg += " * only when weight plot is set to no weight plot"
    21762185        if msg:
    21772186            msg = 'Publication export is only available under limited plot settings\n'+msg
     
    21872196    else:
    21882197        publish = None
    2189     new,plotNum,Page,Plot,limits = G2frame.G2plotNB.FindPlotTab('Powder Patterns','mpl',
    2190                                                                 publish=publish)
     2198    new,plotNum,Page,Plot,limits = G2frame.G2plotNB.FindPlotTab('Powder Patterns','mpl',publish=publish)
    21912199    if not new:
    21922200        G2frame.xylim = limits
     
    22362244                    Page.Choice = (' key press','n: log(I) off',
    22372245                        'c: contour on','q: toggle q plot','t: toggle d-spacing plot',
    2238                             'm: toggle multidata plot','w: toggle divide by sig','+: toggle selection')
     2246                            'm: toggle multidata plot','+: toggle selection')
    22392247                else:
    22402248                    Page.Choice = (' key press','n: log(I) off',
    22412249                        'd: offset down','l: offset left','r: offset right','u: offset up','o: reset offset',
    22422250                        'c: contour on','q: toggle q plot','t: toggle d-spacing plot','f: select data',
    2243                         'm: toggle multidata plot','w: toggle divide by sig','+: toggle selection')
     2251                        'm: toggle multidata plot','+: toggle selection')
    22442252            elif plottype in ['SASD','REFD']:
    22452253                if G2frame.SinglePlot:
     
    22562264                        'b: toggle subtract background','n: log(I) on','s: toggle sqrt plot','c: contour on',
    22572265                        'q: toggle q plot','t: toggle d-spacing plot','m: toggle multidata plot',
    2258                         'w: toggle divide by sig','+: no selection')
     2266                        'w: toggle (Io-Ic)/sig plot','+: no selection')
    22592267                else:
    22602268                    Page.Choice = (' key press','l: offset left','r: offset right','d/D: offset down/10x','u/U: offset up/10x','o: reset offset',
    22612269                        'b: toggle subtract background','n: log(I) on','c: contour on','q: toggle q plot','t: toggle d-spacing plot',
    2262                         'm: toggle multidata plot','f: select data','s: color scheme','w: toggle divide by sig','+: no selection')
     2270                        'm: toggle multidata plot','w: toggle (Io-Ic)/sig plot','f: select data','s: color scheme','+: no selection')
    22632271            elif plottype in ['SASD','REFD']:
    22642272                if G2frame.SinglePlot:
     
    23362344    #Plot.set_title(Title) # show title only w/o magnification
    23372345    if G2frame.plotStyle['qPlot'] or plottype in ['SASD','REFD'] and not G2frame.Contour:
    2338         Plot.set_xlabel(r'$Q, \AA^{-1}$',fontsize=16)
     2346        xLabel = r'$Q, \AA^{-1}$'
    23392347    elif G2frame.plotStyle['dPlot'] and 'PWDR' in plottype and not G2frame.Contour:
    2340         Plot.set_xlabel(r'$d, \AA$',fontsize=16)
     2348        xLabel = r'$d, \AA$'
    23412349    else:
    2342         if 'C' in ParmList[0]['Type'][0]:       
    2343             Plot.set_xlabel(r'$\mathsf{2\theta}$',fontsize=16)
     2350        if 'C' in ParmList[0]['Type'][0]:
     2351            xLabel = r'$\mathsf{2\theta}$'
    23442352        else:
    23452353            if G2frame.Contour:
    2346                 Plot.set_xlabel(r'Channel no.',fontsize=16)           
     2354                xLabel = r'Channel no.'
    23472355            else:
    2348                 Plot.set_xlabel(r'$TOF, \mathsf{\mu}$s',fontsize=16)           
     2356                xLabel = r'$TOF, \mathsf{\mu}$s'
    23492357    if G2frame.Weight:
     2358        Plot.tick_params('x',length=0,labelbottom=False)
     2359        Plot.tick_params('y',length=0,labelleft=False)
     2360        GS_kw = {'height_ratios':[4, 1],}
     2361        Plot,Plot1 = Page.figure.subplots(2,1,sharex=True,gridspec_kw=GS_kw)
     2362        Plot1.set_ylabel(r'$\mathsf{\Delta(I)/\sigma(I)}$',fontsize=16)
     2363        Plot1.set_xlabel(xLabel,fontsize=16)
     2364        Page.figure.subplots_adjust(left=16/100.,bottom=16/150.,
     2365            right=.98,top=1.-16/200.,hspace=0)
     2366    else:
     2367        Plot.set_xlabel(xLabel,fontsize=16)
     2368    if 'C' in ParmList[0]['Type'][0]:
    23502369        if 'PWDR' in plottype:
    2351             Plot.set_ylabel(r'$\mathsf{I/\sigma(I)}$',fontsize=16)
    2352         elif plottype in ['SASD','REFD']:
    2353             Plot.set_ylabel(r'$\mathsf{\Delta(I)/\sigma(I)}$',fontsize=16)
    2354     else:
    2355         if 'C' in ParmList[0]['Type'][0]:
    2356             if 'PWDR' in plottype:
    2357                 if G2frame.plotStyle['sqrtPlot']:
    2358                     Plot.set_ylabel(r'$\sqrt{Intensity}$',fontsize=16)
    2359                 else:
    2360                     Plot.set_ylabel(r'$Intensity$',fontsize=16)
    2361             elif plottype == 'SASD':
    2362                 if G2frame.plotStyle['sqPlot']:
    2363                     Plot.set_ylabel(r'$S(Q)=I*Q^{4}$',fontsize=16)
    2364                 else:
    2365                     Plot.set_ylabel(r'$Intensity,\ cm^{-1}$',fontsize=16)
    2366             elif plottype == 'REFD':
    2367                 if G2frame.plotStyle['sqPlot']:
    2368                     Plot.set_ylabel(r'$S(Q)=R*Q^{4}$',fontsize=16)
    2369                 else:
    2370                     Plot.set_ylabel(r'$Reflectivity$',fontsize=16)               
    2371         else:       #neutron TOF
    23722370            if G2frame.plotStyle['sqrtPlot']:
    2373                 Plot.set_ylabel(r'$\sqrt{Normalized\ intensity}$',fontsize=16)
     2371                Plot.set_ylabel(r'$\sqrt{Intensity}$',fontsize=16)
    23742372            else:
    2375                 Plot.set_ylabel(r'$Normalized\ intensity$',fontsize=16)
     2373                Plot.set_ylabel(r'$Intensity$',fontsize=16)
     2374        elif plottype == 'SASD':
     2375            if G2frame.plotStyle['sqPlot']:
     2376                Plot.set_ylabel(r'$S(Q)=I*Q^{4}$',fontsize=16)
     2377            else:
     2378                Plot.set_ylabel(r'$Intensity,\ cm^{-1}$',fontsize=16)
     2379        elif plottype == 'REFD':
     2380            if G2frame.plotStyle['sqPlot']:
     2381                Plot.set_ylabel(r'$S(Q)=R*Q^{4}$',fontsize=16)
     2382            else:
     2383                Plot.set_ylabel(r'$Reflectivity$',fontsize=16)               
     2384    else:       #neutron TOF
     2385        if G2frame.plotStyle['sqrtPlot']:
     2386            Plot.set_ylabel(r'$\sqrt{Normalized\ intensity}$',fontsize=16)
     2387        else:
     2388            Plot.set_ylabel(r'$Normalized\ intensity$',fontsize=16)
    23762389    mpl.rcParams['image.cmap'] = G2frame.ContourColor
    23772390    mcolors = mpl.cm.ScalarMappable()       #wants only default as defined in previous line!!
     
    25552568                    else:
    25562569                        Plot.set_ylim(bottom=np.min(np.trim_zeros(YB))/2.,top=np.max(Y)*2.)
     2570                if G2frame.Weight:
     2571                    Ibeg = np.searchsorted(X,limits[1][0])
     2572                    Ifin = np.searchsorted(X,limits[1][1])
     2573                    Plot1.set_yscale("linear")                                                 
     2574                    DZ = (xye[1]-xye[3])*np.sqrt(xye[2])
     2575                    DifLine = Plot1.plot(X[Ibeg:Ifin],DZ[Ibeg:Ifin],colors[3],picker=1.,label='_diff')                    #(Io-Ic)/sig(Io)
     2576                    Plot1.axhline(0.,color='k')
     2577                    Plot1.set_ylim(bottom=np.min(DZ[Ibeg:Ifin])*1.2,top=np.max(DZ[Ibeg:Ifin])*1.2) 
    25572578                if G2frame.logPlot:
    25582579                    if 'PWDR' in plottype:
     
    25652586                        Ibeg = np.searchsorted(X,limits[1][0])
    25662587                        Ifin = np.searchsorted(X,limits[1][1])
    2567                         if G2frame.Weight:
    2568                             Plot.set_yscale("linear")
    2569                             DS = (YB-ZB)*np.sqrt(xye[2])
    2570                             Plot.plot(X[Ibeg:Ifin],DS[Ibeg:Ifin],colors[3],picker=False,label='_diff')
    2571                             Plot.axhline(0.,color='k')
    2572                             Plot.set_ylim(bottom=np.min(DS[Ibeg:Ifin])*1.2,top=np.max(DS[Ibeg:Ifin])*1.2)                                                   
     2588                        Plot.set_yscale("log",nonposy='mask')
     2589                        if G2frame.ErrorBars:
     2590                            if G2frame.plotStyle['sqPlot']:
     2591                                Plot.errorbar(X,YB,yerr=X**4*Sample['Scale'][0]*np.sqrt(1./(Pattern[0]['wtFactor']*xye[2])),
     2592                                    ecolor=colors[0],picker=3.,clip_on=Clip_on)
     2593                            else:
     2594                                Plot.errorbar(X,YB,yerr=Sample['Scale'][0]*np.sqrt(1./(Pattern[0]['wtFactor']*xye[2])),
     2595                                    ecolor=colors[0],picker=3.,clip_on=Clip_on,label='_obs')
    25732596                        else:
    2574                             Plot.set_yscale("log",nonposy='mask')
    2575                             if G2frame.ErrorBars:
    2576                                 if G2frame.plotStyle['sqPlot']:
    2577                                     Plot.errorbar(X,YB,yerr=X**4*Sample['Scale'][0]*np.sqrt(1./(Pattern[0]['wtFactor']*xye[2])),
    2578                                         ecolor=colors[0],picker=3.,clip_on=Clip_on)
    2579                                 else:
    2580                                     Plot.errorbar(X,YB,yerr=Sample['Scale'][0]*np.sqrt(1./(Pattern[0]['wtFactor']*xye[2])),
    2581                                         ecolor=colors[0],picker=3.,clip_on=Clip_on,label='_obs')
    2582                             else:
    2583                                 Plot.plot(X,YB,colors[0]+pP,picker=3.,clip_on=Clip_on,label='_obs')
    2584                             Plot.plot(X,W,colors[2],picker=False,label='_bkg')     #const. background
    2585                             Plot.plot(X,ZB,colors[1],picker=False,label='_calc')
    2586                 elif G2frame.Weight and 'PWDR' in plottype:
    2587                     DY = xye[1]*np.sqrt(xye[2])
    2588                     Ymax = max(DY)
    2589                     DZ = xye[3]*np.sqrt(xye[2])
    2590                     DS = xye[5]*np.sqrt(xye[2])-Ymax*Pattern[0]['delOffset']
    2591                     ObsLine = Plot.plot(X,DY,colors[0]+pP,picker=3.,clip_on=Clip_on,label='_obs')         #Io/sig(Io)
    2592                     Plot.plot(X,DZ,colors[1],picker=False,label='_calc')                    #Ic/sig(Io)
    2593                     DifLine = Plot.plot(X,DS,colors[3],picker=1.,label='_diff')                    #(Io-Ic)/sig(Io)
    2594                     Plot.axhline(0.,color='k')
     2597                            Plot.plot(X,YB,colors[0]+pP,picker=3.,clip_on=Clip_on,label='_obs')
     2598                        Plot.plot(X,W,colors[2],picker=False,label='_bkg')     #const. background
     2599                        Plot.plot(X,ZB,colors[1],picker=False,label='_calc')
    25952600                else:
    25962601                    if G2frame.SubBack:
     
    26082613                            Plot.plot(X,YB,colors[0]+pP,picker=3.,clip_on=Clip_on,label='_obs')
    26092614                            Plot.plot(X,ZB,colors[1],picker=False,label='_calc')
    2610                     if 'PWDR' in plottype:
     2615                    if 'PWDR' in plottype: 
    26112616                        Plot.plot(X,W,colors[2],picker=False,label='_bkg')                 #Ib
    2612                         DifLine = Plot.plot(X,D,colors[3],picker=1.,label='_diff')                 #Io-Ic
     2617                        if not G2frame.Weight: DifLine = Plot.plot(X,D,colors[3],picker=1.,label='_diff')                 #Io-Ic
    26132618                    Plot.axhline(0.,color='k',label='_zero')
    26142619                Page.SetToolTipString('')
     
    29202925        '''
    29212926        hcfigure = mpl.figure.Figure(dpi=plotOpt['dpi'],figsize=(plotOpt['width'],plotOpt['height']))
    2922         hccanvas = hcCanvas(hcfigure)
     2927#        hccanvas = hcCanvas(hcfigure)
    29232928        CopyRietveldPlot(G2frame,Pattern,Plot,Page,hcfigure)
    29242929        longFormatName,typ = plotOpt['format'].split(',')
Note: See TracChangeset for help on using the changeset viewer.