Skip to content

Commit 98f2a43

Browse files
committed
Fix tickmarks in plot
1 parent d2db3b9 commit 98f2a43

File tree

1 file changed

+58
-95
lines changed

1 file changed

+58
-95
lines changed

GSASII/GSASIIpwdplot.py

Lines changed: 58 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def OnPlotKeyPress(event):
223223
G2frame.ErrorBars = not G2frame.ErrorBars
224224
elif event.key == 'T' and 'PWDR' in plottype:
225225
Page.plotStyle['title'] = not Page.plotStyle.get('title',True)
226-
elif event.key == 'f' and 'PWDR' in plottype: # short,full length or no tick-marks
226+
elif event.key == 'f' and ('PWDR' in plottype or 'GROUP' in plottype): # short,full length or no tick-marks
227227
if G2frame.Contour: return
228228
Page.plotStyle['flTicks'] = (Page.plotStyle.get('flTicks',0)+1)%3
229229
elif event.key == 'x' and groupName is not None: # share X axis scale for Pattern Groups
@@ -1607,6 +1607,58 @@ def onPartialConfig(event):
16071607
Page.plotStyle['partials'] = True
16081608
Replot()
16091609
configPartialDisplay(G2frame,Page.phaseColors,Replot)
1610+
def adjustDim(i,nx):
1611+
'''MPL creates a 1-D array when nx=1, 2-D otherwise.
1612+
This adjusts the array addressing.
1613+
'''
1614+
if nx == 1:
1615+
return (0,1)
1616+
else:
1617+
return ((0,i),(1,i))
1618+
def drawTicks(Phases,phaseList,group=False):
1619+
'Draw the tickmarcks for phases in the current histogram'
1620+
l = GSASIIpath.GetConfigValue('Tick_length',8.0)
1621+
w = GSASIIpath.GetConfigValue('Tick_width',1.)
1622+
for pId,phase in enumerate(phaseList):
1623+
if 'list' in str(type(Phases[phase])):
1624+
continue
1625+
if phase in Page.phaseColors:
1626+
plcolor = Page.phaseColors[phase]
1627+
else: # how could this happen?
1628+
plcolor = 'k'
1629+
#continue
1630+
peaks = Phases[phase].get('RefList',[])
1631+
if not len(peaks):
1632+
continue
1633+
if Phases[phase].get('Super',False):
1634+
peak = np.array([[peak[5],peak[6]] for peak in peaks])
1635+
else:
1636+
peak = np.array([[peak[4],peak[5]] for peak in peaks])
1637+
if group:
1638+
pos = (2.5-len(phaseList)*5 + pId*5)**np.ones_like(peak) # tick positions hard-coded
1639+
else:
1640+
pos = Page.plotStyle['refOffset']-pId*Page.plotStyle['refDelt']*np.ones_like(peak)
1641+
if Page.plotStyle['qPlot']:
1642+
xtick = 2*np.pi/peak.T[0]
1643+
elif Page.plotStyle['dPlot']:
1644+
xtick = peak.T[0]
1645+
else:
1646+
xtick = peak.T[1]
1647+
if Page.plotStyle.get('flTicks',0) == 0: # short tick-marks
1648+
Page.tickDict[phase],_ = Plot.plot(
1649+
xtick,pos,'|',mew=w,ms=l,picker=True,pickradius=3.,
1650+
label=phase,color=plcolor)
1651+
# N.B. above creates two Line2D objects, 2nd is ignored.
1652+
# Not sure what each does.
1653+
elif Page.plotStyle.get('flTicks',0) == 1: # full length tick-marks
1654+
if len(xtick) > 0:
1655+
# create an ~hidden tickmark to create a legend entry
1656+
Page.tickDict[phase] = Plot.plot(xtick[0],0,'|',mew=0.5,ms=l,
1657+
label=phase,color=plcolor)[0]
1658+
for xt in xtick: # a separate line for each reflection position
1659+
Plot.axvline(xt,color=plcolor,
1660+
picker=True,pickradius=3.,
1661+
label='_FLT_'+phase,lw=0.5)
16101662

16111663
#### beginning PlotPatterns execution #####################################
16121664
global exclLines,Page
@@ -1807,7 +1859,8 @@ def onPartialConfig(event):
18071859
Phases = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId,'Reflection Lists'))
18081860
Page.phaseList = sorted(Phases.keys()) # define an order for phases (once!)
18091861
else:
1810-
Page.phaseList = Phases = []
1862+
Histograms,Phases = G2frame.GetUsedHistogramsAndPhasesfromTree()
1863+
Page.phaseList = Phases
18111864
# assemble a list of validated colors for tickmarks
18121865
valid_colors = []
18131866
invalid_colors = []
@@ -2123,21 +2176,13 @@ def onPartialConfig(event):
21232176
gridspec_kw=GS_kw)
21242177
Page.figure.subplots_adjust(left=5/100.,bottom=16/150.,
21252178
right=.99,top=1.-3/200.,hspace=0,wspace=0)
2126-
def adjustDim(i,nx):
2127-
'''MPL creates a 1-D array when nx=1, 2-D otherwise.
2128-
This adjusts the array addressing.
2129-
'''
2130-
if nx == 1:
2131-
return (0,1)
2132-
else:
2133-
return ((0,i),(1,i))
21342179
for i in range(nx):
21352180
up,down = adjustDim(i,nx)
21362181
Plots[up].set_xlim(gXmin[i],gXmax[i])
21372182
Plots[down].set_xlim(gXmin[i],gXmax[i])
21382183
Plots[down].set_ylim(DZmin,DZmax)
21392184
if not Page.plotStyle.get('flTicks',False):
2140-
Plots[up].set_ylim(-len(Page.phaseList)*5,102)
2185+
Plots[up].set_ylim(-len(RefTbl[i])*5,102)
21412186
else:
21422187
Plots[up].set_ylim(-1,102)
21432188

@@ -2182,51 +2227,7 @@ def adjustDim(i,nx):
21822227
clip_on=Clip_on,label=incCptn('obs'))
21832228
Plot.plot(gX[i],scaleY(xye[3]),pwdrCol['Calc_color'],picker=False,label=incCptn('calc'),linewidth=1.5)
21842229
Plot.plot(gX[i],scaleY(xye[4]),pwdrCol['Bkg_color'],picker=False,label=incCptn('bkg'),linewidth=1.5) #background
2185-
2186-
l = GSASIIpath.GetConfigValue('Tick_length',8.0)
2187-
w = GSASIIpath.GetConfigValue('Tick_width',1.)
2188-
for pId,phase in enumerate(Page.phaseList):
2189-
if 'list' in str(type(Phases[phase])):
2190-
continue
2191-
if phase in Page.phaseColors:
2192-
plcolor = Page.phaseColors[phase]
2193-
else: # how could this happen?
2194-
plcolor = 'k'
2195-
#continue
2196-
peaks = []
2197-
if phase in RefTbl[i]:
2198-
peaks = RefTbl[i][phase].get('RefList',[])
2199-
super = RefTbl[i][phase].get('Super',False)
2200-
# else:
2201-
# peaks = Phases[phase].get('RefList',[])
2202-
# super = Phases[phase].get('Super',False)
2203-
if not len(peaks):
2204-
continue
2205-
if super:
2206-
peak = np.array([[peak[5],peak[6]] for peak in peaks])
2207-
else:
2208-
peak = np.array([[peak[4],peak[5]] for peak in peaks])
2209-
pos = 2.5-len(Page.phaseList)*5 + pId*5 # tick positions hard-coded
2210-
if Page.plotStyle['qPlot']:
2211-
xtick = 2*np.pi/peak.T[0]
2212-
elif Page.plotStyle['dPlot']:
2213-
xtick = peak.T[0]
2214-
else:
2215-
xtick = peak.T[1]
2216-
if not Page.plotStyle.get('flTicks',False): # short tick-marks
2217-
Plot.plot(
2218-
xtick,pos * np.ones_like(peak),
2219-
'|',mew=w,ms=l, # picker=True,pickradius=3.,
2220-
label=phase,color=plcolor)
2221-
else: # full length tick-marks
2222-
if len(xtick) > 0:
2223-
# create an ~hidden tickmark to create a legend entry
2224-
Page.tickDict[phase] = Plot.plot(xtick[0],0,'|',mew=0.5,ms=l,
2225-
label=phase,color=plcolor)[0]
2226-
for xt in xtick: # a separate line for each reflection position
2227-
Plot.axvline(xt,color=plcolor,
2228-
picker=True,pickradius=3.,
2229-
label='_FLT_'+phase,lw=0.5)
2230+
drawTicks(RefTbl[i],list(RefTbl[i].keys()),True)
22302231
try: # try used as in PWDR menu not Groups
22312232
# Not sure if this does anything
22322233
G2frame.dataWindow.moveTickLoc.Enable(False)
@@ -2894,45 +2895,7 @@ def adjustDim(i,nx):
28942895
or (inXtraPeakMode and
28952896
G2frame.GPXtree.GetItemText(G2frame.PickId) == 'Peak List')
28962897
):
2897-
l = GSASIIpath.GetConfigValue('Tick_length',8.0)
2898-
w = GSASIIpath.GetConfigValue('Tick_width',1.)
2899-
for pId,phase in enumerate(Page.phaseList):
2900-
if 'list' in str(type(Phases[phase])):
2901-
continue
2902-
if phase in Page.phaseColors:
2903-
plcolor = Page.phaseColors[phase]
2904-
else: # how could this happen?
2905-
plcolor = 'k'
2906-
#continue
2907-
peaks = Phases[phase].get('RefList',[])
2908-
if not len(peaks):
2909-
continue
2910-
if Phases[phase].get('Super',False):
2911-
peak = np.array([[peak[5],peak[6]] for peak in peaks])
2912-
else:
2913-
peak = np.array([[peak[4],peak[5]] for peak in peaks])
2914-
pos = Page.plotStyle['refOffset']-pId*Page.plotStyle['refDelt']*np.ones_like(peak)
2915-
if Page.plotStyle['qPlot']:
2916-
xtick = 2*np.pi/peak.T[0]
2917-
elif Page.plotStyle['dPlot']:
2918-
xtick = peak.T[0]
2919-
else:
2920-
xtick = peak.T[1]
2921-
if Page.plotStyle.get('flTicks',0) == 0: # short tick-marks
2922-
Page.tickDict[phase],_ = Plot.plot(
2923-
xtick,pos,'|',mew=w,ms=l,picker=True,pickradius=3.,
2924-
label=phase,color=plcolor)
2925-
# N.B. above creates two Line2D objects, 2nd is ignored.
2926-
# Not sure what each does.
2927-
elif Page.plotStyle.get('flTicks',0) == 1: # full length tick-marks
2928-
if len(xtick) > 0:
2929-
# create an ~hidden tickmark to create a legend entry
2930-
Page.tickDict[phase] = Plot.plot(xtick[0],0,'|',mew=0.5,ms=l,
2931-
label=phase,color=plcolor)[0]
2932-
for xt in xtick: # a separate line for each reflection position
2933-
Plot.axvline(xt,color=plcolor,
2934-
picker=True,pickradius=3.,
2935-
label='_FLT_'+phase,lw=0.5)
2898+
drawTicks(Phases,Page.phaseList)
29362899
handles,legends = Plot.get_legend_handles_labels()
29372900
if handles:
29382901
labels = dict(zip(legends,handles)) # remove duplicate phase entries

0 commit comments

Comments
 (0)