Changeset 3392 for trunk/GSASIIplot.py
- Timestamp:
- May 17, 2018 11:27:37 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIplot.py
r3388 r3392 1594 1594 G2frame.HKL (used for tool tip display of hkl for selected phase reflection list) 1595 1595 ''' 1596 def PublishPlot(event): 1597 msg = "" 1598 if 'PWDR' not in plottype: 1599 msg += " * only PWDR histograms can be used" 1600 if G2frame.Contour or not G2frame.SinglePlot: 1601 if msg: msg += '\n' 1602 msg += " * only when a single histogram is plotted" 1603 if Page.plotStyle['logPlot'] or Page.plotStyle['sqrtPlot']: 1604 if msg: msg += '\n' 1605 msg += " * only when the intensity scale is linear (not log or sqrt)" 1606 if G2frame.Weight: 1607 if msg: msg += '\n' 1608 msg += " * only when weight plot is set to no weight plot" 1609 if msg: 1610 msg = 'Publication export is only available under limited plot settings\n'+msg 1611 G2G.G2MessageBox(G2frame,msg,'Wrong plot settings') 1612 print(msg) 1613 else: 1614 PublishRietveldPlot(G2frame,Pattern,Plot,Page) 1615 1596 1616 global exclLines,Page 1597 1617 global DifLine # BHT: probably does not need to be global 1598 1618 global Ymax 1599 global Pattern,mcolors,Plot 1619 global Pattern,mcolors,Plot,Page 1600 1620 plottype = plotType 1601 1621 … … 1608 1628 if data is None: 1609 1629 data = G2frame.GPXtree.GetItemPyData(G2frame.PatternId) 1610 if 'Offset' not in data[0] and plotType in ['PWDR','SASD','REFD']: #plot offset data 1630 if plottype not in ['SASD','REFD'] and 'PWDR' in G2frame.GPXtree.GetItemText(G2frame.PickId): 1631 publish = PublishPlot 1632 else: 1633 publish = None 1634 new,plotNum,Page,Plot,limits = G2frame.G2plotNB.FindPlotTab('Powder Patterns','mpl',publish=publish) 1635 if 'Offset' not in Page.plotStyle and plotType in ['PWDR','SASD','REFD']: #plot offset data 1611 1636 Ymax = max(data[1][1]) 1612 data[0].update({'Offset':[0.0,0.0],'delOffset':0.02*Ymax,'refOffset':-0.1*Ymax,1637 Page.plotStyle.update({'Offset':[0.0,0.0],'delOffset':0.02*Ymax,'refOffset':-0.1*Ymax, 1613 1638 'refDelt':0.1*Ymax,}) 1614 1639 G2frame.GPXtree.SetItemPyData(G2frame.PickId,data) … … 1640 1665 Page.plotStyle['sqrtPlot'] = False 1641 1666 else: 1642 Pa ttern[0]['Offset'][0] = 01667 Page.plotStyle['Offset'][0] = 0 1643 1668 newPlot = True 1644 1669 elif event.key == 's' and 'PWDR' in plottype: … … 1649 1674 Ymax = max(Pattern[1][1]) 1650 1675 if Page.plotStyle['sqrtPlot']: 1651 Pa ttern[0]['delOffset'] = .002*np.sqrt(Ymax)1652 Pa ttern[0]['refOffset'] = -0.1*np.sqrt(Ymax)1653 Pa ttern[0]['refDelt'] = .1*np.sqrt(Ymax)1676 Page.plotStyle['delOffset'] = .002*np.sqrt(Ymax) 1677 Page.plotStyle['refOffset'] = -0.1*np.sqrt(Ymax) 1678 Page.plotStyle['refDelt'] = .1*np.sqrt(Ymax) 1654 1679 else: 1655 Pa ttern[0]['delOffset'] = .02*Ymax1656 Pa ttern[0]['refOffset'] = -0.1*Ymax1657 Pa ttern[0]['refDelt'] = .1*Ymax1680 Page.plotStyle['delOffset'] = .02*Ymax 1681 Page.plotStyle['refOffset'] = -0.1*Ymax 1682 Page.plotStyle['refDelt'] = .1*Ymax 1658 1683 else: #select color scheme for multiplots & contour plots 1659 1684 choice = [m for m in mpl.cm.datad.keys()] # if not m.endswith("_r") … … 1670 1695 if G2frame.Contour: 1671 1696 G2frame.Cmax = min(1.0,G2frame.Cmax*1.2) 1672 elif Pa ttern[0]['Offset'][0] < 100.:1673 Pa ttern[0]['Offset'][0] += 1.1697 elif Page.plotStyle['Offset'][0] < 100.: 1698 Page.plotStyle['Offset'][0] += 1. 1674 1699 elif event.key == 'd' and (G2frame.Contour or not G2frame.SinglePlot): 1675 1700 if G2frame.Contour: 1676 1701 G2frame.Cmax = max(0.0,G2frame.Cmax*0.8) 1677 elif Pa ttern[0]['Offset'][0] > -100.:1678 Pa ttern[0]['Offset'][0] -= 1.1702 elif Page.plotStyle['Offset'][0] > -100.: 1703 Page.plotStyle['Offset'][0] -= 1. 1679 1704 elif event.key == 'U': 1680 1705 if G2frame.Contour: 1681 1706 G2frame.Cmin += (G2frame.Cmax - G2frame.Cmin)/5. 1682 elif Pa ttern[0]['Offset'][0] < 100.:1683 Pa ttern[0]['Offset'][0] += 10.1707 elif Page.plotStyle['Offset'][0] < 100.: 1708 Page.plotStyle['Offset'][0] += 10. 1684 1709 elif event.key == 'D': 1685 1710 if G2frame.Contour: 1686 1711 G2frame.Cmin -= (G2frame.Cmax - G2frame.Cmin)/5. 1687 elif Pa ttern[0]['Offset'][0] > -100.:1688 Pa ttern[0]['Offset'][0] -= 10.1712 elif Page.plotStyle['Offset'][0] > -100.: 1713 Page.plotStyle['Offset'][0] -= 10. 1689 1714 elif event.key == 'l' and not G2frame.SinglePlot: 1690 Pa ttern[0]['Offset'][1] -= 1.1715 Page.plotStyle['Offset'][1] -= 1. 1691 1716 elif event.key == 'r' and not G2frame.SinglePlot: 1692 Pa ttern[0]['Offset'][1] += 1.1717 Page.plotStyle['Offset'][1] += 1. 1693 1718 elif event.key == 'o' and not G2frame.SinglePlot: 1694 1719 G2frame.Cmax = 1.0 1695 Pa ttern[0]['Offset'] = [0,0]1720 Page.plotStyle['Offset'] = [0,0] 1696 1721 elif event.key == 'c' and 'PWDR' in plottype: 1697 1722 newPlot = True 1698 1723 if not G2frame.Contour: 1699 1724 G2frame.SinglePlot = False 1700 Pa ttern[0]['Offset'] = [0.,0.]1725 Page.plotStyle['Offset'] = [0.,0.] 1701 1726 else: 1702 1727 G2frame.SinglePlot = True … … 1746 1771 elif event.key == 'm': 1747 1772 Page.plotStyle['sqrtPlot'] = False 1748 G2frame.SinglePlot = not G2frame.SinglePlot 1773 if not G2frame.Contour: 1774 G2frame.SinglePlot = not G2frame.SinglePlot 1775 G2frame.Contour = False 1749 1776 newPlot = True 1750 1777 elif event.key == 'f' and not G2frame.SinglePlot: … … 1961 1988 Page.canvas.restore_region(savedplot) 1962 1989 if Page.pickTicknum: 1963 refDelt = -(event.ydata-Pa ttern[0]['refOffset'])/Page.pickTicknum1964 refOffset = Pa ttern[0]['refOffset']1990 refDelt = -(event.ydata-Page.plotStyle['refOffset'])/Page.pickTicknum 1991 refOffset = Page.plotStyle['refOffset'] 1965 1992 else: #1st row of refl ticks 1966 1993 refOffset = event.ydata 1967 refDelt = Pa ttern[0]['refDelt']1994 refDelt = Page.plotStyle['refDelt'] 1968 1995 for pId,phase in enumerate(Page.phaseList): 1969 1996 pos = refOffset - pId*refDelt … … 2084 2111 Page.canvas.draw() # save bitmap 2085 2112 savedplot = Page.canvas.copy_from_bbox(Page.figure.gca().bbox) 2086 Page.diffOffset = Pa ttern[0]['delOffset']2113 Page.diffOffset = Page.plotStyle['delOffset'] 2087 2114 G2frame.cid = Page.canvas.mpl_connect('motion_notify_event', OnDragDiffCurve) 2088 2115 elif G2frame.itemPicked in G2frame.MagLines: # drag of magnification marker … … 2205 2232 data = G2frame.GPXtree.GetItemPyData(PickId) 2206 2233 ypos = event.ydata 2207 Pa ttern[0]['delOffset'] = -ypos2234 Page.plotStyle['delOffset'] = -ypos 2208 2235 G2frame.itemPicked = None 2209 2236 wx.CallAfter(PlotPatterns,G2frame,plotType=plottype) … … 2291 2318 num = Page.phaseList.index(pick) 2292 2319 if num: 2293 data[0]['refDelt'] = -(event.ydata-Pattern[0]['refOffset'])/num2320 Page.plotStyle['refDelt'] = -(event.ydata-Page.plotStyle['refOffset'])/num 2294 2321 else: #1st row of refl ticks 2295 data[0]['refOffset'] = event.ydata2322 Page.plotStyle['refOffset'] = event.ydata 2296 2323 PlotPatterns(G2frame,plotType=plottype) 2297 2324 G2frame.itemPicked = None 2298 2325 2299 def PublishPlot(event):2300 msg = ""2301 if 'PWDR' not in plottype:2302 msg += " * only PWDR histograms can be used"2303 if G2frame.Contour or not G2frame.SinglePlot:2304 if msg: msg += '\n'2305 msg += " * only when a single histogram is plotted"2306 if Page.plotStyle['logPlot'] or Page.plotStyle['sqrtPlot']:2307 if msg: msg += '\n'2308 msg += " * only when the intensity scale is linear (not log or sqrt)"2309 if G2frame.Weight:2310 if msg: msg += '\n'2311 msg += " * only when weight plot is set to no weight plot"2312 if msg:2313 msg = 'Publication export is only available under limited plot settings\n'+msg2314 G2G.G2MessageBox(G2frame,msg,'Wrong plot settings')2315 print(msg)2316 else:2317 PublishRietveldPlot(G2frame,Pattern,Plot,Page)2318 2319 2326 #===================================================================================== 2320 2327 # beginning PlotPatterns execution 2321 if plottype not in ['SASD','REFD'] and 'PWDR' in G2frame.GPXtree.GetItemText(G2frame.PickId):2322 publish = PublishPlot2323 else:2324 publish = None2325 new,plotNum,Page,Plot,limits = G2frame.G2plotNB.FindPlotTab('Powder Patterns','mpl',publish=publish)2326 2328 if not new: 2327 2329 G2frame.xylim = limits … … 2424 2426 exclLines = [] 2425 2427 if G2frame.SinglePlot and PatternId: 2426 Pattern = copy.deepcopy(G2frame.GPXtree.GetItemPyData(PatternId)) 2428 # Pattern = copy.deepcopy(G2frame.GPXtree.GetItemPyData(PatternId)) 2429 Pattern = G2frame.GPXtree.GetItemPyData(PatternId) 2427 2430 Pattern.append(G2frame.GPXtree.GetItemText(PatternId)) 2428 2431 PlotList = [Pattern,] … … 2450 2453 for item in choices: 2451 2454 id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root, item) 2452 Pattern = copy.deepcopy(G2frame.GPXtree.GetItemPyData(id)) 2455 Pattern = G2frame.GPXtree.GetItemPyData(id) 2456 # Pattern = copy.deepcopy(G2frame.GPXtree.GetItemPyData(id)) 2453 2457 if len(Pattern) < 3: # put name on end if needed 2454 2458 Pattern.append(G2frame.GPXtree.GetItemText(id)) 2455 if 'Offset' not in Pa ttern[0]: #plot offset data2459 if 'Offset' not in Page.plotStyle: #plot offset data 2456 2460 Ymax = max(Pattern[1][1]) 2457 Pa ttern[0].update({'Offset':[0.0,0.0],'delOffset':0.02*Ymax,'refOffset':-0.1*Ymax,'refDelt':0.1*Ymax,})2461 Page.plotStyle.update({'Offset':[0.0,0.0],'delOffset':0.02*Ymax,'refOffset':-0.1*Ymax,'refDelt':0.1*Ymax,}) 2458 2462 PId = G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Background') 2459 2463 Pattern[0]['BackFile'] = ['',-1.0] … … 2478 2482 Ymax = max(Ymax,max(xye[1]+bxye)) 2479 2483 if Ymax is None: return # nothing to plot 2480 offsetX = Pa ttern[0]['Offset'][1]2481 offsetY = Pa ttern[0]['Offset'][0]2484 offsetX = Page.plotStyle['Offset'][1] 2485 offsetY = Page.plotStyle['Offset'][0] 2482 2486 if Page.plotStyle['logPlot']: 2483 2487 Title = 'log('+Title+')' … … 2552 2556 excls = limits[2:] 2553 2557 xye0 = ma.array(xye0,mask=False) 2554 # xye0.mask = False # resets mask for xye0 & Pattern[1][0](!)2555 xye0 = ma.masked_outside(xye0,limits[1][0],limits[1][1])2556 2558 for excl in excls: 2557 xye0 = ma.masked_inside(xye0,excl[0],excl[1]) # sets mask on xye0 but not Pattern[1][0] ! 2558 Pattern[1][0] = ma.array(Pattern[1][0],mask=ma.getmask(xye0)) 2559 # Pattern[1][0].mask = xye0.mask # transfer the mask 2559 xye0 = ma.masked_inside(xye0,excl[0],excl[1]) #excluded region mask 2560 Pattern[1][0] = ma.array(Pattern[1][0],mask=ma.getmask(xye0)) #save the excluded region masking 2561 if not G2frame.Contour: 2562 xye0 = ma.masked_outside(xye0,limits[1][0],limits[1][1]) #now mask for limits 2560 2563 if Page.plotStyle['qPlot'] and 'PWDR' in plottype: 2561 2564 X = 2.*np.pi/G2lat.Pos2dsp(Parms,xye0) … … 2608 2611 magMarkers.append(Plot.axvline(x,color='0.5',dashes=(1,1),picker=2.,label='_magline')) 2609 2612 lbl = Plot.annotate("x{}".format(ml), xy=(x, tpos), xycoords=("data", "axes fraction"), 2610 2613 verticalalignment='bottom',horizontalalignment=halign,label='_maglbl') 2611 2614 Plot.magLbls.append(lbl) 2612 2615 if ml0: 2613 2616 lbl = Plot.annotate("x{}".format(ml0), xy=(tcorner, tpos), xycoords="axes fraction", 2614 2617 verticalalignment='bottom',horizontalalignment=halign,label='_maglbl') 2615 2618 Plot.magLbls.append(lbl) 2616 2619 Page.toolbar.updateActions = (PlotPatterns,G2frame) … … 2691 2694 W = np.where(xye[4]>=0.,np.sqrt(xye[4]),-np.sqrt(-xye[4])) 2692 2695 np.seterr(invalid=olderr['invalid']) 2693 D = np.where(xye[5],(Y-Z),0.)-Pa ttern[0]['delOffset']2696 D = np.where(xye[5],(Y-Z),0.)-Page.plotStyle['delOffset'] 2694 2697 elif 'PWDR' in plottype and G2frame.SinglePlot and not ( 2695 2698 Page.plotStyle['logPlot'] or Page.plotStyle['sqrtPlot'] or G2frame.Contour): 2696 2699 W = xye[4]*multArray+NoffY*Ymax/100.0 2697 D = multArray*xye[5]-Pa ttern[0]['delOffset'] #powder background2700 D = multArray*xye[5]-Page.plotStyle['delOffset'] #powder background 2698 2701 else: 2699 2702 W = xye[4]+NoffY*Ymax/100.0 2700 D = xye[5]-Pa ttern[0]['delOffset'] #powder background2703 D = xye[5]-Page.plotStyle['delOffset'] #powder background 2701 2704 elif plottype in ['SASD','REFD']: 2702 2705 if Page.plotStyle['sqPlot']: … … 2779 2782 Ni = N 2780 2783 if Page.plotStyle['qPlot']: 2781 Lines.append(Plot.axvline(2.*np.pi/G2lat.Pos2dsp(Parms,item[0]),color= colors[Ni%6],picker=2.))2784 Lines.append(Plot.axvline(2.*np.pi/G2lat.Pos2dsp(Parms,item[0]),color='b',picker=2.)) 2782 2785 elif Page.plotStyle['dPlot']: 2783 Lines.append(Plot.axvline(G2lat.Pos2dsp(Parms,item[0]),color= colors[Ni%6],picker=2.))2786 Lines.append(Plot.axvline(G2lat.Pos2dsp(Parms,item[0]),color='b',picker=2.)) 2784 2787 else: 2785 Lines.append(Plot.axvline(item[0],color= colors[Ni%6],picker=2.))2788 Lines.append(Plot.axvline(item[0],color='b',picker=2.)) 2786 2789 if Ni == N+1: 2787 2790 Lines[-1].set_lw(Lines[-1].get_lw()+1) … … 2852 2855 else: 2853 2856 peak = np.array([[peak[4],peak[5]] for peak in peaks]) 2854 pos = Pa ttern[0]['refOffset']-pId*Pattern[0]['refDelt']*np.ones_like(peak)2855 plsym = Page.phaseColors .get(phase,'y')+'|' # yellow should never happen!2857 pos = Page.plotStyle['refOffset']-pId*Page.plotStyle['refDelt']*np.ones_like(peak) 2858 plsym = Page.phaseColors[phase]+'|' # yellow should never happen! 2856 2859 if Page.plotStyle['qPlot']: 2857 2860 Page.tickDict[phase],j = Plot.plot(2*np.pi/peak.T[0],pos,plsym,mew=w,ms=l,picker=3.,label=phase) … … 3341 3344 # save information needed to reload from tree and redraw 3342 3345 G2frame.G2plotNB.RegisterRedrawRoutine(G2frame.G2plotNB.lastRaisedPlotTab, 3343 PlotDeltSig,( 3344 G2frame,kind, 3345 G2frame.GPXtree.GetItemText(G2frame.PatternId)) 3346 ) 3346 PlotDeltSig,(G2frame,kind,G2frame.GPXtree.GetItemText(G2frame.PatternId))) 3347 3347 Page.Choice = None 3348 3348 PatternId = G2frame.PatternId
Note: See TracChangeset
for help on using the changeset viewer.