Changeset 4004 for trunk/GSASIIplot.py
- Timestamp:
- May 30, 2019 1:40:09 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIplot.py
r4003 r4004 256 256 plotOpt['fmtChoices'] = {} 257 257 plotOpt['lineWid'] = '1' 258 259 def Write2csv(fil,dataItems,header=False): 260 '''Write a line to a CSV file 261 262 :param object fil: file object 263 :param list dataItems: items to write as row in file 264 :param bool header: True if all items should be written with quotes (default is False) 265 ''' 266 line = '' 267 for item in dataItems: 268 if line: line += ',' 269 item = str(item) 270 if header or ' ' in item: 271 line += '"'+item+'"' 272 else: 273 line += item 274 fil.write(line+'\n') 258 275 259 276 def MPLsubplots(figure, nrows=1, ncols=1, sharex=False, sharey=False, … … 3469 3486 figure.canvas.draw() 3470 3487 3471 def Write2csv(fil,dataItems,header=False):3472 '''Write a line to a CSV file3473 3474 :param object fil: file object3475 :param list dataItems: items to write as row in file3476 :param bool header: True if all items should be written with quotes (default is False)3477 '''3478 line = ''3479 for item in dataItems:3480 if line: line += ','3481 item = str(item)3482 if header or ' ' in item:3483 line += '"'+item+'"'3484 else:3485 line += item3486 fil.write(line+'\n')3487 3488 3488 # blocks of code used in grace .agr files 3489 3489 linedef = '''@{0} legend "{1}" … … 5307 5307 if event.key == 'g': 5308 5308 mpl.rcParams['axes.grid'] = not mpl.rcParams['axes.grid'] 5309 elif event.key == 's': 5310 # write the function values (not peaks) onto a file 5311 dlg = wx.FileDialog(G2frame, 'Choose CSV file to write', 5312 wildcard='column-separated file (*.csv)|.csv', 5313 style=wx.FD_CHANGE_DIR|wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) 5314 try: 5315 if dlg.ShowModal() == wx.ID_OK: 5316 filename = dlg.GetPath() 5317 else: 5318 return 5319 finally: 5320 dlg.Destroy() 5321 fp = open(filename,'w') 5322 fp.write("# Peak widths. Def. are default values from InstParms file, fit are from refined Instrument Parameters\n") 5323 if 'C' in Parms['Type'][0]: 5324 Write2csv(fp,['Q', 5325 'Gauss-def','Lorenz-def,total-def', 5326 'Gauss-fit','Lorenz-fit,total-fit'] 5327 ,header=True) 5328 for vals in zip(Q,Y,Z,W,Yf,Zf,Wf): Write2csv(fp,vals) 5329 else: 5330 Write2csv(fp,['Q', 5331 'Gauss-def','Lorenz-def', 5332 'Gauss-fit','Lorenz-fit',] 5333 ,header=True) 5334 for vals in zip(Q,S,G,Sf,Gf): Write2csv(fp,vals) 5335 fp.close() 5309 5336 wx.CallAfter(PlotPeakWidths,G2frame,PatternName) 5310 5337 … … 5337 5364 xylim = [] 5338 5365 new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Peak Widths','mpl') 5339 Page.Choice = (' key press','g: toggle grid', )5366 Page.Choice = (' key press','g: toggle grid','s: save as .csv file') 5340 5367 Page.keyPress = OnKeyPress 5341 5368 if not new: … … 5387 5414 Plot.plot(Q,Wf,color='b',dashes=(5,5),label='G+L fit') 5388 5415 5389 X = []5390 Y = []5391 Z = []5392 W = []5416 Xp = [] 5417 Yp = [] 5418 Zp = [] 5419 Wp = [] 5393 5420 for peak in peaks: 5394 X .append(4.0*math.pi*sind(peak[0]/2.0)/lam)5421 Xp.append(4.0*math.pi*sind(peak[0]/2.0)/lam) 5395 5422 try: 5396 5423 s = math.sqrt(peak[4])*math.pi/18000. … … 5399 5426 g = peak[6]*math.pi/18000. 5400 5427 G = G2pwd.getgamFW(g,s) #/2. 5401 Y .append(sq8ln2*s/tand(peak[0]/2.))5402 Z .append(g/tand(peak[0]/2.))5403 W .append(G/tand(peak[0]/2.))5428 Yp.append(sq8ln2*s/tand(peak[0]/2.)) 5429 Zp.append(g/tand(peak[0]/2.)) 5430 Wp.append(G/tand(peak[0]/2.)) 5404 5431 if len(peaks): 5405 Plot.plot(X ,Y,'+',color='r',label='G peak')5406 Plot.plot(X ,Z,'+',color='g',label='L peak')5407 Plot.plot(X ,W,'+',color='b',label='G+L peak')5432 Plot.plot(Xp,Yp,'+',color='r',label='G peak') 5433 Plot.plot(Xp,Zp,'+',color='g',label='L peak') 5434 Plot.plot(Xp,Wp,'+',color='b',label='G+L peak') 5408 5435 legend = Plot.legend(loc='best') 5409 5436 SetupLegendPick(legend,new) … … 5440 5467 Plot.plot(Q,Gf,color='m',dashes=(5,5),label='Lorentzian fit') 5441 5468 5442 T = []5443 A = []5444 B = []5445 S = []5446 G = []5447 W = []5448 Q = []5469 Tp = [] 5470 Ap = [] 5471 Bp = [] 5472 Sp = [] 5473 Gp = [] 5474 Wp = [] 5475 Qp = [] 5449 5476 for peak in peaks: 5450 T .append(peak[0])5451 A .append(peak[4])5452 B .append(peak[6])5453 Q .append(2.*np.pi*difC/peak[0])5454 S .append(1.17741*np.sqrt(peak[8])/peak[0])5455 G .append(peak[10]/peak[0])5477 Tp.append(peak[0]) 5478 Ap.append(peak[4]) 5479 Bp.append(peak[6]) 5480 Qp.append(2.*np.pi*difC/peak[0]) 5481 Sp.append(1.17741*np.sqrt(peak[8])/peak[0]) 5482 Gp.append(peak[10]/peak[0]) 5456 5483 5457 5458 Plot.plot(Q,A,'+',color='r',label='Alpha peak')5459 Plot.plot(Q,B,'+',color='g',label='Beta peak')5460 Plot.plot(Q,S,'+',color='b',label='Gaussian peak')5461 Plot.plot(Q,G,'+',color='m',label='Lorentzian peak')5484 if Qp: 5485 Plot.plot(Qp,Ap,'+',color='r',label='Alpha peak') 5486 Plot.plot(Qp,Bp,'+',color='g',label='Beta peak') 5487 Plot.plot(Qp,Sp,'+',color='b',label='Gaussian peak') 5488 Plot.plot(Qp,Gp,'+',color='m',label='Lorentzian peak') 5462 5489 Plot.legend(loc='best') 5463 5490 if xylim and not G2frame.G2plotNB.allowZoomReset:
Note: See TracChangeset
for help on using the changeset viewer.