Skip to content

Commit 9e0a3d0

Browse files
committed
prevent rescaling of plots when not needed; fix bug in unequally stepped contour plots; minor contour plot formatting
1 parent 8ed50d8 commit 9e0a3d0

2 files changed

Lines changed: 61 additions & 23 deletions

File tree

GSASII/GSASIIdataGUI.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8512,11 +8512,20 @@ def OnEditMag(**args):
85128512
G2frame.GPXtree.SetItemPyData(item,data)
85138513
G2frame.PatternId = item
85148514
if kind in ['PWDR','SASD','REFD',]:
8515-
NewPlot = True
8516-
if 'Contour' in dir(G2frame) and G2frame.Contour:
8517-
pass
8518-
elif 'xylim' in dir(G2frame):
8515+
# When I added code to allow for contour plots from unequally spaced data
8516+
# I forced all contour plots to replot with newPlot=True. I'm not sure if
8517+
# this is actually needed and for autointegration we really don't want
8518+
# plots to rescale.
8519+
# NewPlot = True
8520+
# if getattr(G2frame,'Contour',False):
8521+
# pass
8522+
# if hasattr(G2frame,'xylim'):
8523+
# NewPlot = False
8524+
# now only rescale when needed
8525+
if hasattr(G2frame,'xylim'):
85198526
NewPlot = False
8527+
else:
8528+
NewPlot = True
85208529
# if GSASIIpath.GetConfigValue('debug'):
85218530
# from importlib import reload
85228531
# reload(G2pwpl)
@@ -8964,16 +8973,21 @@ def OnShowShift(event):
89648973
G2pdG.UpdatePeakGrid(G2frame,data)
89658974
for i in G2frame.ExportPeakList: i.Enable(True)
89668975
newPlot = False
8967-
if hasattr(G2frame,'Contour'):
8968-
if G2frame.Contour:
8969-
G2frame.Contour = False
8970-
newPlot = True
8976+
if getattr(G2frame,'Contour','False'):
8977+
G2frame.Contour = False
8978+
newPlot = True
89718979
G2pwpl.PlotPatterns(G2frame,newPlot,fromTree=True)
89728980
elif G2frame.GPXtree.GetItemText(item) == 'Background':
8981+
NewPlot = False # plot using previous limits
8982+
if getattr(G2frame,'Contour',False): # except if contour plot
8983+
G2frame.Contour = False
8984+
NewPlot = True
8985+
elif not hasattr(G2frame,'xylim'): # or no limits present
8986+
NewPlot = True
89738987
G2frame.PatternId = G2frame.GPXtree.GetItemParent(item)
89748988
data = G2frame.GPXtree.GetItemPyData(item)
89758989
G2pdG.UpdateBackground(G2frame,data)
8976-
G2pwpl.PlotPatterns(G2frame,True,fromTree=True)
8990+
G2pwpl.PlotPatterns(G2frame,newPlot=NewPlot,fromTree=True)
89778991
elif G2frame.GPXtree.GetItemText(item) == 'Limits':
89788992
G2frame.PatternId = G2frame.GPXtree.GetItemParent(item)
89798993
datatype = G2frame.GPXtree.GetItemText(G2frame.PatternId)[:4]
@@ -9035,10 +9049,9 @@ def OnShowShift(event):
90359049
G2plt.PlotPowderLines(G2frame)
90369050
else:
90379051
newPlot = False
9038-
if hasattr(G2frame,'Contour'):
9039-
if G2frame.Contour:
9040-
G2frame.Contour = False
9041-
newPlot = True
9052+
if getattr(G2frame,'Contour','False'):
9053+
G2frame.Contour = False
9054+
newPlot = True
90429055
G2pwpl.PlotPatterns(G2frame,newPlot,fromTree=True)
90439056
elif G2frame.GPXtree.GetItemText(item) == 'Unit Cells List':
90449057
G2frame.PatternId = G2frame.GPXtree.GetItemParent(item)
@@ -9066,10 +9079,9 @@ def OnShowShift(event):
90669079
G2pdG.UpdateReflectionGrid(G2frame,data)
90679080
G2frame.dataWindow.HideShow.Enable(False)
90689081
newPlot = False
9069-
if hasattr(G2frame,'Contour'):
9070-
if G2frame.Contour:
9071-
G2frame.Contour = False
9072-
newPlot = True
9082+
if getattr(G2frame,'Contour','False'):
9083+
G2frame.Contour = False
9084+
newPlot = True
90739085
G2pwpl.PlotPatterns(G2frame,newPlot,fromTree=True)
90749086
elif G2frame.GPXtree.GetItemText(item) == 'Reflection List': #HKLF reflections
90759087
G2frame.PatternId = G2frame.GPXtree.GetItemParent(item)

GSASII/GSASIIpwdplot.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,11 +2137,16 @@ def onPartialConfig(event):
21372137

21382138
# convert all X values and then reapply mask if xye0 is a masked array
21392139
mask = None
2140-
if hasattr(xye0,'mask'): mask = xye0.mask
2140+
if hasattr(xye0,'mask'):
2141+
mask = xye0.mask
2142+
X = xye0.data
2143+
else:
2144+
mask = None
2145+
X = xye0
21412146
if Page.plotStyle['qPlot'] and 'PWDR' in plottype and not ifLimits:
2142-
X = ma.array(2.*np.pi/G2lat.Pos2dsp(Parms,xye0.data),mask=mask)
2147+
X = ma.array(2.*np.pi/G2lat.Pos2dsp(Parms,X),mask=mask)
21432148
elif Page.plotStyle['dPlot'] and 'PWDR' in plottype and not ifLimits:
2144-
X = ma.array(G2lat.Pos2dsp(Parms,xye0.data),mask=mask)
2149+
X = ma.array(G2lat.Pos2dsp(Parms,X),mask=mask)
21452150
else:
21462151
X = copy.deepcopy(xye0)
21472152
if ifpicked and not G2frame.Contour:
@@ -2482,7 +2487,10 @@ def onPartialConfig(event):
24822487

24832488
G2plt.Write2csv(fp,['masked X','X','obs','calc','bkg','diff'],header=True)
24842489
for i in range(len(X)):
2485-
G2plt.Write2csv(fp,[X[i],X.data[i],Y[i],Z[i],W[i],D[i]],header=False)
2490+
if hasattr(X,'mask'):
2491+
G2plt.Write2csv(fp,[X[i],X.data[i],Y[i],Z[i],W[i],D[i]],header=False)
2492+
else:
2493+
G2plt.Write2csv(fp,[X[i],X[i],Y[i],Z[i],W[i],D[i]],header=False)
24862494
fp.close()
24872495
print('file',plotOpt['CSVfile'],'written')
24882496

@@ -2726,7 +2734,7 @@ def onPartialConfig(event):
27262734
siz = 6
27272735
elif len(legends) > 15:
27282736
siz = 8
2729-
lngd = Plot.legend(handles,legends,title=msg,loc='best',
2737+
Plot.legend(handles,legends,title=msg,loc='best',
27302738
fontsize=siz)
27312739
if G2frame.Contour:
27322740
time0 = time.time()
@@ -2850,7 +2858,7 @@ def onPartialConfig(event):
28502858
# Page.toolbar.set_history_buttons() # this may be needed to update the zoom buttons (needs test)
28512859
# Page.canvas.draw_idle() # schedule an MPL update (needs test)
28522860
if G2frame.Contour: # for contour plots expand y-axis to include all histograms
2853-
G2frame.xylim = (G2frame.xylim[0], (0.,len(PlotList)))
2861+
G2frame.xylim = (G2frame.xylim[0], (-0.5,len(PlotList)-0.5))
28542862
if 'PWDR' in plottype:
28552863
Plot.set_xlim(G2frame.xylim[0])
28562864
Plot.set_ylim(G2frame.xylim[1])
@@ -2861,6 +2869,24 @@ def onPartialConfig(event):
28612869
else:
28622870
G2frame.xylim = Plot.get_xlim(),Plot.get_ylim()
28632871
Page.canvas.draw()
2872+
if G2frame.Contour: # for contour plots remove non-integer yaxis labels as they are a distraction
2873+
labels = []
2874+
vals = []
2875+
for item in Plot.get_yticklabels():
2876+
lbl = item.get_text()
2877+
try:
2878+
val = float(lbl.replace('\u2212', '-'))
2879+
if int(val) != val:
2880+
continue
2881+
elif val < 0 or val > G2frame.xylim[1][1]: # out of range labels not needed
2882+
continue
2883+
else:
2884+
vals.append(val)
2885+
labels.append(str(int(val)))
2886+
except:
2887+
pass
2888+
Plot.yaxis.set_ticks(vals,labels)
2889+
Page.canvas.draw()
28642890
olderr = np.seterr(invalid='ignore') #ugh - this removes a matplotlib error for mouse clicks in log plots
28652891
# and sqrt(-ve) in np.where usage
28662892
if 'PWDR' in G2frame.GPXtree.GetItemText(G2frame.PickId):

0 commit comments

Comments
 (0)