Changeset 4298
- Timestamp:
- Feb 12, 2020 5:39:55 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIplot.py
r4294 r4298 201 201 Angstr = chr(0x00c5) 202 202 Pwrm1 = chr(0x207b)+chr(0x0b9) 203 # misc global vars 203 204 nxs = np.newaxis 204 205 plotDebug = False 205 206 timeDebug = GSASIIpath.GetConfigValue('Show_timing',False) 207 obsInCaption = True # include the observed, calc,... items in the plot caption (PlotPatterns) 206 208 207 209 #matplotlib 2.0.x dumbed down Paired to 16 colors - … … 1823 1825 if msg: msg += '\n' 1824 1826 msg += " * only when a single histogram is plotted" 1825 if Page.plotStyle['logPlot'] or Page.plotStyle['sqrtPlot']:1827 if Page.plotStyle['logPlot']: 1826 1828 if msg: msg += '\n' 1827 msg += " * only when the intensity scale is linear (not log or sqrt)"1829 msg += " * only when the intensity scale is linear/sqrt (not log)" 1828 1830 if G2frame.Weight: 1829 1831 if msg: msg += '\n' … … 1919 1921 elif event.key == 'r' and not G2frame.SinglePlot: 1920 1922 Page.plotStyle['Offset'][1] += 1. 1921 elif event.key == 'o' and not G2frame.SinglePlot: 1922 G2frame.Cmax = 1.0 1923 G2frame.Cmin = 0.0 1924 Page.plotStyle['Offset'] = [0,0] 1923 elif event.key == 'o': 1924 if G2frame.SinglePlot and not G2frame.Contour: 1925 global obsInCaption # include the observed, calc,... items in the plot caption (PlotPatterns) 1926 obsInCaption = not obsInCaption 1927 elif not G2frame.SinglePlot: 1928 G2frame.Cmax = 1.0 1929 G2frame.Cmin = 0.0 1930 Page.plotStyle['Offset'] = [0,0] 1925 1931 elif event.key == 'c' and 'PWDR' in plottype: 1926 1932 newPlot = True … … 2014 2020 else: 2015 2021 #print('no binding for key',event.key) 2016 #GSASIIpath.IPyBreak()2017 2022 return 2018 2023 wx.CallAfter(PlotPatterns,G2frame,newPlot=newPlot,plotType=plottype,extraKeys=extraKeys) … … 2720 2725 Plot.set_title(Title) 2721 2726 Page.canvas.draw() 2727 def incCptn(string): 2728 '''Adds a underscore to "hide" a MPL object from the legend if 2729 obsInCaption is False 2730 ''' 2731 if obsInCaption: 2732 return string 2733 else: 2734 return '_'+string 2722 2735 2723 2736 #===================================================================================== … … 2784 2797 G2frame.Cmin = 0.0 2785 2798 G2frame.Cmax = 1.0 2786 # Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress)2787 2799 Page.canvas.mpl_connect('motion_notify_event', OnMotion) 2788 2800 Page.canvas.mpl_connect('pick_event', OnPick) … … 2837 2849 'a: add magnification region','b: toggle subtract background', 2838 2850 'c: contour on','g: toggle grid','m: toggle multidata plot', 2839 'n: toggle log(I)','q: toggle q plot','s: toggle sqrt plot', 2851 'n: toggle log(I)',] 2852 if obsInCaption: 2853 Page.Choice += ['o: remove obs, calc,... from legend',] 2854 else: 2855 Page.Choice += ['o: add obs, calc,... to legend',] 2856 Page.Choice += ['q: toggle q plot','s: toggle sqrt plot', 2840 2857 't: toggle d-spacing plot','w: toggle (Io-Ic)/sig plot', 2841 2858 '+: no selection'] … … 3215 3232 else: 3216 3233 DZ = (xye[1]-xye[3])*np.sqrt(wtFactor*xye[2]) 3217 DifLine = Plot1.plot(X,DZ,colors[3],picker=1.,label= '_diff') #(Io-Ic)/sig(Io)3234 DifLine = Plot1.plot(X,DZ,colors[3],picker=1.,label=incCptn('diff')) #(Io-Ic)/sig(Io) 3218 3235 Plot1.axhline(0.,color='k') 3219 3236 … … 3221 3238 if 'PWDR' in plottype: 3222 3239 Plot.set_yscale("log",nonposy='mask') 3223 Plot.plot(X,Y,colors[0]+pP,picker=3.,clip_on=Clip_on,label= '_obs')3240 Plot.plot(X,Y,colors[0]+pP,picker=3.,clip_on=Clip_on,label=incCptn('obs')) 3224 3241 if G2frame.SinglePlot or G2frame.plusPlot: 3225 Plot.plot(X,Z,colors[1],picker=False,label= '_calc')3242 Plot.plot(X,Z,colors[1],picker=False,label=incCptn('calc')) 3226 3243 if G2frame.plusPlot: 3227 Plot.plot(X,W,colors[2],picker=False,label= '_bkg') #background3244 Plot.plot(X,W,colors[2],picker=False,label=incCptn('bkg')) #background 3228 3245 elif plottype in ['SASD','REFD']: 3229 3246 Plot.set_xscale("log",nonposx='mask') … … 3235 3252 else: 3236 3253 Plot.errorbar(X,YB,yerr=Sample['Scale'][0]*np.sqrt(1./(Pattern[0]['wtFactor']*xye[2])), 3237 ecolor=colors[0],picker=3.,clip_on=Clip_on,label= '_obs')3254 ecolor=colors[0],picker=3.,clip_on=Clip_on,label=incCptn('obs')) 3238 3255 else: 3239 Plot.plot(X,YB,colors[0]+pP,picker=3.,clip_on=Clip_on,label= '_obs')3240 Plot.plot(X,W,colors[1],picker=False,label= '_bkg') #const. background3241 Plot.plot(X,ZB,colors[2],picker=False,label= '_calc')3256 Plot.plot(X,YB,colors[0]+pP,picker=3.,clip_on=Clip_on,label=incCptn('obs')) 3257 Plot.plot(X,W,colors[1],picker=False,label=incCptn('bkg')) #const. background 3258 Plot.plot(X,ZB,colors[2],picker=False,label=incCptn('calc')) 3242 3259 else: # not logPlot 3243 3260 if G2frame.SubBack: 3244 3261 if 'PWDR' in plottype: 3245 ObsLine = Plot.plot(Xum,Y,colors[0]+pP,picker=False,clip_on=Clip_on,label= '_obs-bkg') #Io-Ib3262 ObsLine = Plot.plot(Xum,Y,colors[0]+pP,picker=False,clip_on=Clip_on,label=incCptn('obs-bkg')) #Io-Ib 3246 3263 if np.any(Z): #only if there is a calc pattern 3247 CalcLine = Plot.plot(X,Z-W,colors[1],picker=False,label= '_calc-bkg') #Ic-Ib3264 CalcLine = Plot.plot(X,Z-W,colors[1],picker=False,label=incCptn('calc-bkg')) #Ic-Ib 3248 3265 else: 3249 Plot.plot(X,YB,colors[0]+pP,picker=3.,clip_on=Clip_on,label= '_obs')3250 Plot.plot(X,ZB,colors[2],picker=False,label= '_calc')3266 Plot.plot(X,YB,colors[0]+pP,picker=3.,clip_on=Clip_on,label=incCptn('obs')) 3267 Plot.plot(X,ZB,colors[2],picker=False,label=incCptn('calc')) 3251 3268 else: 3252 3269 if 'PWDR' in plottype: 3253 ObsLine = Plot.plot(Xum,Y,colors[0]+pP,picker=3.,clip_on=Clip_on,label= '_obs') #Io3254 CalcLine = Plot.plot(X,Z,colors[1],picker=False,label= '_calc') #Ic3270 ObsLine = Plot.plot(Xum,Y,colors[0]+pP,picker=3.,clip_on=Clip_on,label=incCptn('obs')) #Io 3271 CalcLine = Plot.plot(X,Z,colors[1],picker=False,label=incCptn('calc')) #Ic 3255 3272 else: 3256 Plot.plot(X,YB,colors[0]+pP,picker=3.,clip_on=Clip_on,label= '_obs')3257 Plot.plot(X,ZB,colors[2],picker=False,label= '_calc')3273 Plot.plot(X,YB,colors[0]+pP,picker=3.,clip_on=Clip_on,label=incCptn('obs')) 3274 Plot.plot(X,ZB,colors[2],picker=False,label=incCptn('calc')) 3258 3275 if 'PWDR' in plottype and (G2frame.SinglePlot and G2frame.plusPlot): 3259 BackLine = Plot.plot(X,W,colors[2],picker=False,label= '_bkg') #Ib3260 if not G2frame.Weight and np.any(Z): 3261 DifLine = Plot.plot(X,D,colors[3],picker=1.,label= '_diff') #Io-Ic3276 BackLine = Plot.plot(X,W,colors[2],picker=False,label=incCptn('bkg')) #Ib 3277 if not G2frame.Weight and np.any(Z): 3278 DifLine = Plot.plot(X,D,colors[3],picker=1.,label=incCptn('diff')) #Io-Ic 3262 3279 Plot.axhline(0.,color='k',label='_zero') 3263 3280 Page.SetToolTipString('') … … 3369 3386 handles = [labels[item] for item in labels] 3370 3387 legends = list(labels.keys()) 3371 Plot.legend(handles,legends,title='Phases',loc='best') 3372 3388 if len(Phases) and obsInCaption: 3389 Plot.legend(handles,legends,title='Phases & Data',loc='best') 3390 else: 3391 Plot.legend(handles,legends,title='Data',loc='best') 3392 3373 3393 if G2frame.Contour: 3374 3394 time0 = time.time() … … 3490 3510 if 'mag' in lbl: 3491 3511 pass 3492 elif lbl[1:] in plotOpt['lineList']: 3512 elif lbl[1:] in plotOpt['lineList']: # item not in legend 3493 3513 if lbl[1:] in plotOpt['colors']: continue 3494 3514 plotOpt['colors'][lbl[1:]] = MPL2rgba(l.get_color()) 3495 3515 plotOpt['legend'][lbl[1:]] = False 3516 elif lbl in plotOpt['lineList']: 3517 if lbl in plotOpt['colors']: continue 3518 plotOpt['colors'][lbl] = MPL2rgba(l.get_color()) 3519 plotOpt['legend'][lbl] = True 3496 3520 elif l in Page.tickDict.values(): 3497 3521 plotOpt['phaseList'] .append(lbl) … … 3603 3627 fp.write('@{}axis tick major {}\n'.format('y',yticks[1]-yticks[0])) 3604 3628 fp.write('@{}axis ticklabel char size {}\n'.format('x',0)) # turns off axis labels 3605 ylbl = Plot.get_ylabel().replace('$','') 3629 if 'sqrt' in Plot.yaxis.get_label().get_text(): 3630 ylbl = 'sqrt(Intensity)' # perhaps there is a way to get the symbol in xmgrace but I did not find it 3631 else: 3632 ylbl = 'Intensity' 3606 3633 fp.write('@{0}axis label "{1}"\n@{0}axis label char size {2}\n'.format( 3607 3634 'y',ylbl,float(plotOpt['labelSize'])/8.)) … … 3641 3668 # plot data 3642 3669 for l in Plot.lines: 3643 lbl = l.get_label() 3644 if lbl[1:] not in ('obs','calc','bkg','zero','diff'): continue 3645 c = plotOpt['colors'].get(lbl[1:],l.get_color()) 3670 if l.get_label() in ('obs','calc','bkg','zero','diff'): 3671 lbl = l.get_label() 3672 elif l.get_label()[1:] in ('obs','calc','bkg','zero','diff'): 3673 lbl = l.get_label()[1:] 3674 else: 3675 continue 3676 c = plotOpt['colors'].get(lbl,l.get_color()) 3646 3677 gc = ClosestColorNumber(c) 3647 3678 if sum(c) == 4.0: # white on white, skip … … 3652 3683 mkwid = l.get_mew() 3653 3684 glinetyp = 1 3654 if lbl [1:]== 'obs':3685 if lbl == 'obs': 3655 3686 obsartist = l 3656 3687 gsiz = float(plotOpt['markerSiz'])/8. … … 3664 3695 gmw = 0 3665 3696 lineWid = float(plotOpt['lineWid']) 3666 if plotOpt['legend'].get(lbl [1:]):3667 glbl = lbl [1:]3697 if plotOpt['legend'].get(lbl): 3698 glbl = lbl 3668 3699 else: 3669 3700 glbl = "" 3670 3701 datnum += 1 3671 3702 fp.write("@type xy\n") 3672 if lbl [1:]== 'zero':3703 if lbl == 'zero': 3673 3704 fp.write("{} {}\n".format(Plot.get_xlim()[0],0)) 3674 3705 fp.write("{} {}\n".format(Plot.get_xlim()[1],0)) … … 3807 3838 if plotOpt['legend'].get(lbl[1:]): 3808 3839 legends.append((InameDict[lbl[1:]],lbl[1:])) 3809 if 'mag' in lbl: 3810 pass 3811 elif lbl[1:] in ('obs','calc','bkg','zero','diff'): 3812 if lbl[1:] == 'obs': 3813 x = l.get_xdata() 3814 valueList.append(x) 3815 zerovals = (x.min(),x.max()) 3816 gsiz = 5*float(plotOpt['markerSiz'])/8. 3817 marker = plotOpt['markerSym'] 3818 gsym = igor_symbols.get(marker,12) 3819 gmw = float(plotOpt['markerWid']) 3820 markerSettings.append( 3821 'mode({0})=3,marker({0})={1},msize({0})={2},mrkThick({0})={3}' 3822 .format('Intensity',gsym,gsiz,gmw)) 3823 else: 3824 markerSettings.append( 3825 'mode({0})=0, lsize({0})={1}' 3826 .format(InameDict[lbl[1:]],plotOpt['lineWid'])) 3827 c = plotOpt['colors'].get(lbl[1:],l.get_color()) 3828 #if sum(c) == 4.0: continue 3829 Icolor[InameDict[lbl[1:]]] = [j*65535 for j in c[0:3]] 3830 if lbl[1:] != 'zero': 3831 valueList.append(l.get_ydata()) 3840 if l.get_label()[1:] in ('obs','calc','bkg','zero','diff'): 3841 lbl = l.get_label()[1:] 3842 if plotOpt['legend'].get(lbl) and lbl in InameDict: 3843 legends.append((InameDict[lbl],lbl)) 3844 if lbl == 'obs': 3845 x = l.get_xdata() 3846 valueList.append(x) 3847 zerovals = (x.min(),x.max()) 3848 gsiz = 5*float(plotOpt['markerSiz'])/8. 3849 marker = plotOpt['markerSym'] 3850 gsym = igor_symbols.get(marker,12) 3851 gmw = float(plotOpt['markerWid']) 3852 markerSettings.append( 3853 'mode({0})=3,marker({0})={1},msize({0})={2},mrkThick({0})={3}' 3854 .format('Intensity',gsym,gsiz,gmw)) 3855 elif lbl in ('calc','bkg','zero','diff'): 3856 markerSettings.append( 3857 'mode({0})=0, lsize({0})={1}' 3858 .format(InameDict[lbl],plotOpt['lineWid'])) 3859 else: 3860 continue 3861 c = plotOpt['colors'].get(lbl,l.get_color()) 3862 #if sum(c) == 4.0: continue 3863 Icolor[InameDict[lbl]] = [j*65535 for j in c[0:3]] 3864 if lbl != 'zero': 3865 valueList.append(l.get_ydata()) 3832 3866 valueList.append(Pattern[1][5]*np.sqrt(Pattern[1][2])) 3833 3867 # invert lists into columns, use iterator for all values … … 3885 3919 fp.write(' {0} 0.0\n {1} 0.0\n'.format(*zerovals)) 3886 3920 fp.write('END\nX AppendToGraph Zero vs ZeroX\n') 3921 if 'sqrt' in Plot.yaxis.get_label().get_text(): 3922 ylabel = '\u221AIntensity' 3923 else: 3924 ylabel = 'Intensity' 3887 3925 fp.write('''X // *** add axis labels and position them 3888 3926 X Label left "{1}" … … 3890 3928 X Label bottom "{0}" 3891 3929 X ModifyGraph lblPosMode=0,lblPos(Res_left)=84 3892 '''.format("2Î", "Intensity","â/Ï"))3930 '''.format("2Î",ylabel,"â/Ï")) 3893 3931 fp.write('''X // *** set display limits. 3894 3932 X SetAxis left {2}, {3} … … 3985 4023 tickpos = {} 3986 4024 for i,l in enumerate(Plot.lines): 3987 lbl = l.get_label() 4025 if l.get_label() in ('obs','calc','bkg','zero','diff'): 4026 lbl = l.get_label() 4027 elif l.get_label()[1:] in ('obs','calc','bkg','zero','diff'): 4028 lbl = l.get_label()[1:] 4029 else: 4030 lbl = l.get_label() 3988 4031 if 'mag' in lbl: 3989 4032 pass 3990 elif lbl [1:]in ('obs','calc','bkg','zero','diff'):3991 if lbl [1:]== 'obs':4033 elif lbl in ('obs','calc','bkg','zero','diff'): 4034 if lbl == 'obs': 3992 4035 lblList.append('x') 3993 4036 valueList.append(l.get_xdata()) 3994 c = plotOpt['colors'].get(lbl [1:],l.get_color())4037 c = plotOpt['colors'].get(lbl,l.get_color()) 3995 4038 if sum(c) == 4.0: continue 3996 4039 lblList.append(lbl) … … 4149 4192 gsizer.Add(wx.StaticText(dlg,wx.ID_ANY,'Include in legend'),0,wx.ALL) 4150 4193 for lbl in list(plotOpt['lineList']) + list(plotOpt['phaseList'] ): 4194 if lbl not in plotOpt['legend']: 4195 plotOpt['legend'][lbl] = False 4151 4196 ch = G2G.G2CheckBox(dlg,'',plotOpt['legend'],lbl,RefreshPlot) 4152 4197 gsizer.Add(ch,0,wx.ALL|wx.ALIGN_CENTER) … … 4155 4200 for lbl in list(plotOpt['lineList']) + list(plotOpt['phaseList']): 4156 4201 import wx.lib.colourselect as csel 4202 if lbl not in plotOpt['colors']: 4203 plotOpt['colors'][lbl] = (0.5, 0.5, 0.5, 1) 4157 4204 color = wx.Colour(*[int(255*i) for i in plotOpt['colors'][lbl]]) 4158 4205 b = csel.ColourSelect(dlg, -1, '', color) … … 4249 4296 obsartist = None 4250 4297 for i,l in enumerate(Plot.lines): 4251 lbl = l.get_label() 4298 if l.get_label() in ('obs','calc','bkg','zero','diff'): 4299 lbl = l.get_label() 4300 elif l.get_label()[1:] in ('obs','calc','bkg','zero','diff'): 4301 lbl = l.get_label()[1:] 4302 else: 4303 lbl = l.get_label() 4252 4304 if 'mag' in lbl: 4253 4305 ax0.axvline(l.get_data()[0][0],color='0.5',dashes=(1,1)) 4254 elif lbl [1:]in ('obs','calc','bkg','zero','diff'):4306 elif lbl in ('obs','calc','bkg','zero','diff'): 4255 4307 marker = l.get_marker() 4256 4308 lineWid = l.get_lw() 4257 4309 siz = l.get_markersize() 4258 4310 mew = l.get_mew() 4259 if lbl [1:]== 'obs':4311 if lbl == 'obs': 4260 4312 obsartist = l 4261 4313 siz = float(plotOpt['markerSiz']) … … 4264 4316 else: 4265 4317 lineWid = float(plotOpt['lineWid']) 4266 c = plotOpt['colors'].get(lbl [1:],l.get_color())4318 c = plotOpt['colors'].get(lbl,l.get_color()) 4267 4319 if sum(c) == 4.0: continue 4268 if plotOpt['legend'].get(lbl [1:]):4269 uselbl = lbl [1:]4320 if plotOpt['legend'].get(lbl): 4321 uselbl = lbl 4270 4322 else: 4271 uselbl = lbl4272 if lbl [1:]== 'zero':4323 uselbl = '_'+lbl 4324 if lbl == 'zero': 4273 4325 art = [ax0.axhline(0.,color=c, 4274 4326 lw=lineWid,label=uselbl,ls=l.get_ls(), … … 4279 4331 marker=marker,ms=siz,mew=mew, 4280 4332 ) 4281 if plotOpt['legend'].get(lbl [1:]):4333 if plotOpt['legend'].get(lbl): 4282 4334 legLbl.append(uselbl) 4283 4335 legLine.append(art[0]) -
trunk/makeBat.py
r4266 r4298 13 13 14 14 ''' 15 from __future__ import division, print_function 15 16 version = "$Id$" 16 17 # creates Windows files to aid in running GSAS-II
Note: See TracChangeset
for help on using the changeset viewer.