Skip to content

Commit 681763b

Browse files
committed
more work on preventing limit resets; this should replace everything in PR #285
1 parent c8e308b commit 681763b

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

GSASII/GSASIIplot.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,31 +474,31 @@ def FindPlotTab(self,label,Type,newImage=True,saveLimits=False):
474474
Page.toolbar.enableArrows() # Disable Arrow keys if present
475475
return new,plotNum,Page,Plot,limits
476476

477-
def savePlotLims(self,Page):
477+
def savePlotLims(self,Page,debug=False):
478478
'''Make a copy of all the current axes in the notebook object
479479
'''
480480
self.savedPlotLims = [
481481
[i.get_xlim() for i in Page.figure.get_axes()],
482482
[i.get_ylim() for i in Page.figure.get_axes()]]
483-
#print(f'saved {len(self.savedPlotLims[1])} axes limits')
484-
483+
if debug:
484+
print(f'saved {len(self.savedPlotLims[1])} axes limits')
485+
#print( self.savedPlotLims)
485486
def restoreSavedPlotLims(self,Page):
486487
'''Restore the plot limits, when previously saved, and when
487488
``G2frame.restorePlotLimits`` is set to True, which
488489
is done when ``GSASIIpwdplot.refPlotUpdate`` is called with
489-
``restore=True``, which indicates that "live plotting" is done.
490+
``restore=True``, which indicates that "live plotting" is
491+
finished. This is also set for certain plot key-press
492+
combinations.
490493
The restore operation can only be done once, as the limits
491494
are deleted after use in this method.
492495
'''
493496
if self.savedPlotLims is None:
494497
#print('---- nothing to restore')
495498
return
496-
if not hasattr(self.G2frame,'restorePlotLimits'):
499+
if not getattr(self.G2frame,'restorePlotLimits',False):
497500
#print('---- restorePlotLimits not set')
498501
return
499-
if not self.G2frame.restorePlotLimits:
500-
#print('---- restorePlotLimits: not yet')
501-
return
502502
savedPlotLims = self.savedPlotLims
503503
axesList = Page.figure.get_axes()
504504
if len(axesList) != len(savedPlotLims[0]):

GSASII/GSASIIpwdplot.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,17 @@ def OnPlotKeyPress(event):
188188
except TypeError:
189189
G2frame.G2plotNB.status.SetStatusText(f'Select {plottype} pattern first',1)
190190
return
191+
if 'GROUP' in plottype: # save plot limits in case we want to restore them
192+
G2frame.G2plotNB.savePlotLims(Page)
191193
newPlot = False
192-
if event.key == 'w':
194+
if event.key == 'w' and not 'GROUP' in plottype:
193195
G2frame.Weight = not G2frame.Weight
194196
if not G2frame.Weight and not G2frame.Contour and 'PWDR' in plottype:
195197
G2frame.SinglePlot = True
196198
elif 'PWDR' in plottype: # Turning on Weight plot clears previous limits
197199
G2frame.FixedLimits['dylims'] = ['','']
198200
#newPlot = True # this resets the x & y limits, not wanted!
199-
elif event.key in ['shift+1','!']: # save current plot settings as defaults
201+
elif event.key in ['shift+1','!'] and not 'GROUP' in plottype: # save current plot settings as defaults
200202
# shift+1 assumes US keyboard
201203
print('saving plotting defaults for',G2frame.GPXtree.GetItemText(G2frame.PatternId))
202204
data = G2frame.GPXtree.GetItemPyData(G2frame.PatternId)
@@ -213,6 +215,7 @@ def OnPlotKeyPress(event):
213215
elif event.key == 'f' and ('PWDR' in plottype or 'GROUP' in plottype): # short,full length or no tick-marks
214216
if G2frame.Contour: return
215217
Page.plotStyle['flTicks'] = (Page.plotStyle.get('flTicks',0)+1)%3
218+
if 'GROUP' in plottype: G2frame.restorePlotLimits = True
216219
elif event.key == 'x' and groupName is not None: # share X axis scale for Pattern Groups
217220
plotOpt['sharedX'] = not plotOpt['sharedX']
218221
# Clear saved x-limits when toggling sharedX mode (MG/Cl Sonnet)
@@ -304,6 +307,7 @@ def OnPlotKeyPress(event):
304307
elif Page.plotStyle['Offset'][0] > -100.:
305308
Page.plotStyle['Offset'][0] -= 10.
306309
elif event.key == 'g':
310+
if 'GROUP' in plottype: G2frame.restorePlotLimits = True
307311
mpl.rcParams['axes.grid'] = not mpl.rcParams['axes.grid']
308312
elif event.key == 'l' and not G2frame.SinglePlot:
309313
Page.plotStyle['Offset'][1] -= 1.
@@ -2257,7 +2261,7 @@ def onGroupXlimChanged(ax):
22572261
Page.Choice = [' key press',
22582262
'f: toggle full-length ticks',
22592263
'g: toggle grid',
2260-
's: toggle sqrt plot',
2264+
#'s: toggle sqrt plot', # TODO: implement this
22612265
'q: toggle Q plot',
22622266
't: toggle d-spacing plot',
22632267
'x: share x-axes (Q/d only)']
@@ -2326,7 +2330,7 @@ def onGroupXlimChanged(ax):
23262330
totalrange += gXmax[i]-gXmin[i]
23272331
if plotOpt['sharedX'] and (
23282332
Page.plotStyle['qPlot'] or Page.plotStyle['dPlot']):
2329-
Page.figure.text(0.001,0.94,'X shared',fontsize=11,
2333+
Page.figure.text(0.94,0.03,'X shared',fontsize=10,
23302334
color='g')
23312335
GS_kw = {'height_ratios':[4, 1]}
23322336
#Plots = Page.figure.subplots(2,Page.groupN,sharey='row',sharex=True,
@@ -2484,8 +2488,8 @@ def onGroupXlimChanged(ax):
24842488
(Page.plotStyle['qPlot'] or Page.plotStyle['dPlot'])):
24852489
up,down = adjustDim(0,Page.groupN)
24862490
G2frame.groupXlim = Plots[up].get_xlim()
2491+
wx.CallAfter(G2frame.G2plotNB.restoreSavedPlotLims,Page) # restore limits to previous, if saved & requested
24872492
Page.canvas.draw()
2488-
wx.CallLater(100,G2frame.G2plotNB.restoreSavedPlotLims,Page) # restore limits to previous, if saved
24892493
return # end of group plot
24902494
elif G2frame.Weight and not G2frame.Contour:
24912495
Plot.set_visible(False) #hide old plot frame, will get replaced below

0 commit comments

Comments
 (0)