@@ -134,7 +134,7 @@ def plotVline(Page,Plot,Lines,Parms,pos,color,pick,style='dotted'):
134134 picker = pick ,pickradius = 2. ,linestyle = style ))
135135
136136def PlotPatterns (G2frame ,newPlot = False ,plotType = 'PWDR' ,data = None ,
137- extraKeys = [],refineMode = False ,indexFrom = '' ):
137+ extraKeys = [],refineMode = False ,indexFrom = '' , fromTree = False ):
138138 '''Powder pattern plotting package - displays single or multiple powder
139139 patterns as intensity vs 2-theta, q or TOF. Can display multiple patterns
140140 as "waterfall plots" or contour plots. Log I plotting available.
@@ -152,6 +152,21 @@ def PlotPatterns(G2frame,newPlot=False,plotType='PWDR',data=None,
152152 reflection list.
153153 * G2frame.Extinct: used for display of extinct reflections (in blue)
154154 for generated reflections when "show extinct" is selected.
155+
156+ :param wx.Frame G2frame: main GSAS-II window
157+ :param newPlot: Set to True when a new type of plot is drawn (default False)
158+ :param plotType: Type of data entry to be plotted (SASD, REFD, PWDR)
159+ (default is 'PWDR')
160+ :param list data: Contents of histogram
161+ :param list extraKeys: list of str values with extra "command" keys to
162+ act on plot
163+ :param bool refineMode: Set to True when called from inside a refinement
164+ default is False
165+ :param str indexFrom: Status line message used to label indexing results
166+ :param bool fromTree: will be set to True when called from the data tree
167+
168+ :returns: if refineMode is True, returns a reference to
169+ :func:`refPlotUpdate`. Otherwise, nothing is returned
155170 '''
156171 global PlotList ,IndxFrom
157172 IndxFrom = indexFrom
@@ -193,6 +208,11 @@ def OnPlotKeyPress(event):
193208 elif 'PWDR' in plottype : # Turning on Weight plot clears previous limits
194209 G2frame .FixedLimits ['dylims' ] = ['' ,'' ]
195210 newPlot = True
211+ elif event .key in ['shift+1' ,'!' ]: # save current plot settings as defaults
212+ print ('saving plotting defaults for' ,G2frame .GPXtree .GetItemText (G2frame .PatternId ))
213+ data = G2frame .GPXtree .GetItemPyData (G2frame .PatternId )
214+ data [0 ]['PlotDefaults' ] = copy .deepcopy ([
215+ Plot .get_xlim (),Plot .get_ylim (),Page .plotStyle ])
196216 elif event .key == 'X' and plottype == 'PWDR' :
197217 G2frame .CumeChi = not G2frame .CumeChi
198218 elif event .key == 'e' and plottype in ['SASD' ,'REFD' ]:
@@ -225,13 +245,13 @@ def OnPlotKeyPress(event):
225245 G2frame .SubBack = False
226246 YmaxS = max (Pattern [1 ][1 ])
227247 if Page .plotStyle ['sqrtPlot' ]:
228- Page .plotStyle ['delOffset' ] = .02 * np .sqrt (YmaxS )
229- Page .plotStyle ['refOffset' ] = - 0.1 * np .sqrt (YmaxS )
230- Page .plotStyle ['refDelt' ] = .1 * np .sqrt (YmaxS )
248+ Page .plotStyle ['delOffset' ] = float ( .02 * np .sqrt (YmaxS ) )
249+ Page .plotStyle ['refOffset' ] = float ( - 0.1 * np .sqrt (YmaxS ) )
250+ Page .plotStyle ['refDelt' ] = float ( .1 * np .sqrt (YmaxS ) )
231251 else :
232- Page .plotStyle ['delOffset' ] = .02 * YmaxS
233- Page .plotStyle ['refOffset' ] = - 0.1 * YmaxS
234- Page .plotStyle ['refDelt' ] = .1 * YmaxS
252+ Page .plotStyle ['delOffset' ] = float ( .02 * YmaxS )
253+ Page .plotStyle ['refOffset' ] = float ( - 0.1 * YmaxS )
254+ Page .plotStyle ['refDelt' ] = float ( .1 * YmaxS )
235255 newPlot = True
236256 elif event .key == 'S' and 'PWDR' in plottype :
237257 choice = [m for m in mpl .cm .datad .keys ()]+ ['GSPaired' ,'GSPaired_r' ,] # if not m.endswith("_r")
@@ -337,11 +357,11 @@ def OnPlotKeyPress(event):
337357 plotType = plottype ,extraKeys = extraKeys )
338358 if abs (Page .startExclReg - event .xdata ) < 0.1 : return
339359 LimitId = G2gd .GetGPXtreeItemId (G2frame ,G2frame .PatternId , 'Limits' )
340- data = G2frame .GPXtree .GetItemPyData (LimitId )
360+ limdat = G2frame .GPXtree .GetItemPyData (LimitId )
341361 mn = min (Page .startExclReg , event .xdata )
342362 mx = max (Page .startExclReg , event .xdata )
343- data .append ([mn ,mx ])
344- G2pdG .UpdateLimitsGrid (G2frame ,data ,plottype )
363+ limdat .append ([mn ,mx ])
364+ G2pdG .UpdateLimitsGrid (G2frame ,limdat ,plottype )
345365 return
346366 elif event .key == 'a' and 'PWDR' in plottype and G2frame .SinglePlot and not (
347367 Page .plotStyle ['logPlot' ] or Page .plotStyle ['sqrtPlot' ] or G2frame .Contour ):
@@ -410,7 +430,7 @@ def OnPlotKeyPress(event):
410430 G2frame .plusPlot = (G2frame .plusPlot + 1 )% 3
411431 elif event .key == '/' :
412432 Page .plotStyle ['Normalize' ] = not Page .plotStyle ['Normalize' ]
413- newPlot = True
433+ newPlot = True
414434 elif event .key == 'i' and G2frame .Contour : #for smoothing contour plot
415435 choice = ['nearest' ,'bilinear' ,'bicubic' ,'spline16' ,'spline36' ,'hanning' ,
416436 'hamming' ,'hermite' ,'kaiser' ,'quadric' ,'catrom' ,'gaussian' ,'bessel' ,
@@ -1163,7 +1183,7 @@ def OnRelease(event):
11631183 if DifLine [0 ] is G2frame .itemPicked : # respond to dragging of the difference curve
11641184 data = G2frame .GPXtree .GetItemPyData (G2frame .PickId )
11651185 ypos = event .ydata
1166- Page .plotStyle ['delOffset' ] = - ypos
1186+ Page .plotStyle ['delOffset' ] = float ( - ypos )
11671187 G2frame .itemPicked = None
11681188 wx .CallAfter (PlotPatterns ,G2frame ,plotType = plottype ,extraKeys = extraKeys )
11691189 return
@@ -1555,9 +1575,9 @@ def onPartialConfig(event):
15551575 Replot ()
15561576 configPartialDisplay (G2frame ,Page .phaseColors ,Replot )
15571577
1558- #### beginning PlotPatterns execution
1578+ #### beginning PlotPatterns execution #####################################
15591579 global exclLines ,Page
1560- global DifLine # BHT: probably does not need to be global
1580+ global DifLine
15611581 global Ymax
15621582 global Pattern ,mcolors ,Plot ,Page ,imgAx ,Temps
15631583 global savedX
@@ -1600,8 +1620,10 @@ def onPartialConfig(event):
16001620#patch
16011621 if 'Offset' not in Page .plotStyle and plotType in ['PWDR' ,'SASD' ,'REFD' ]: #plot offset data
16021622 Ymax = max (data [1 ][1 ])
1603- Page .plotStyle .update ({'Offset' :[0.0 ,0.0 ],'delOffset' :0.02 * Ymax ,'refOffset' :- 0.1 * Ymax ,
1604- 'refDelt' :0.1 * Ymax ,})
1623+ Page .plotStyle .update ({'Offset' :[0.0 ,0.0 ],
1624+ 'delOffset' :float (0.02 * Ymax ),
1625+ 'refOffset' :float (- 0.1 * Ymax ),
1626+ 'refDelt' :float (0.1 * Ymax ),})
16051627#end patch
16061628 if 'Normalize' not in Page .plotStyle :
16071629 Page .plotStyle ['Normalize' ] = False
@@ -1619,18 +1641,17 @@ def onPartialConfig(event):
16191641 print ('triggering newplot from G2frame.lastPlotType' )
16201642 Ymax = max (data [1 ][1 ])
16211643 if Page .plotStyle ['sqrtPlot' ]:
1622- Page .plotStyle ['delOffset' ] = .02 * np .sqrt (Ymax )
1623- Page .plotStyle ['refOffset' ] = - 0.1 * np .sqrt (Ymax )
1624- Page .plotStyle ['refDelt' ] = .1 * np .sqrt (Ymax )
1644+ Page .plotStyle ['delOffset' ] = float ( .02 * np .sqrt (Ymax ) )
1645+ Page .plotStyle ['refOffset' ] = float ( - 0.1 * np .sqrt (Ymax ) )
1646+ Page .plotStyle ['refDelt' ] = float ( .1 * np .sqrt (Ymax ) )
16251647 else :
1626- Page .plotStyle ['delOffset' ] = .02 * Ymax
1627- Page .plotStyle ['refOffset' ] = - 0.1 * Ymax
1628- Page .plotStyle ['refDelt' ] = .1 * Ymax
1648+ Page .plotStyle ['delOffset' ] = float ( .02 * Ymax )
1649+ Page .plotStyle ['refOffset' ] = float ( - 0.1 * Ymax )
1650+ Page .plotStyle ['refDelt' ] = float ( .1 * Ymax )
16291651 newPlot = True
16301652 G2frame .lastPlotType = Parms ['Type' ][1 ]
16311653 except TypeError : #bad id from GetGPXtreeItemId - skip
16321654 pass
1633-
16341655 try :
16351656 G2frame .FixedLimits
16361657 except :
@@ -1671,9 +1692,15 @@ def onPartialConfig(event):
16711692 G2frame .GPXtree .SelectItem (G2frame .PatternId )
16721693 PlotPatterns (G2frame ,True ,plotType ,None ,extraKeys )
16731694 #=====================================================================================
1674- if not new :
1695+ elif 'PlotDefaults' in data [0 ] and fromTree : # set style from defaults saved with '!'
1696+ #print('setting plot style defaults')
1697+ xlim ,ylim ,styleDict = data [0 ]['PlotDefaults' ]
1698+ Page .plotStyle = copy .copy (styleDict )
1699+ newPlot = True # prevent carrying limits over (may not be needed here)
1700+ #=====================================================================================
1701+ if not new : # plotting in previously created axes
16751702 G2frame .xylim = copy .copy (limits )
1676- else :
1703+ else : # 1st time plot is created
16771704 if plottype in ['SASD' ,'REFD' ]:
16781705 Page .plotStyle ['logPlot' ] = True
16791706 G2frame .ErrorBars = True
@@ -1824,6 +1851,7 @@ def onPartialConfig(event):
18241851 Page .Choice = Page .Choice + ['p: toggle partials (if available)' ,]
18251852 if G2frame .SinglePlot :
18261853 Page .Choice += ['v: CSV output of plot' ]
1854+ Page .Choice += ['!: Save settings as default for histogram' ]
18271855 elif plottype in ['SASD' ,'REFD' ]:
18281856 Page .Choice = [' key press' ,
18291857 'b: toggle subtract background file' ,'g: toggle grid' ,
@@ -1906,7 +1934,10 @@ def onPartialConfig(event):
19061934 Pattern .append (G2frame .GPXtree .GetItemText (pid ))
19071935 if 'Offset' not in Page .plotStyle : #plot offset data
19081936 Ymax = max (Pattern [1 ][1 ])
1909- Page .plotStyle .update ({'Offset' :[0.0 ,0.0 ],'delOffset' :0.02 * Ymax ,'refOffset' :- 0.1 * Ymax ,'refDelt' :0.1 * Ymax ,})
1937+ Page .plotStyle .update ({'Offset' :[0.0 ,0.0 ],
1938+ 'delOffset' :float (0.02 * Ymax ),
1939+ 'refOffset' :float (- 0.1 * Ymax ),
1940+ 'refDelt' :float (0.1 * Ymax ),})
19101941 # PId = G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Background')
19111942 # Pattern[0]['BackFile'] = ['',-1.0,False]
19121943 # if PId:
@@ -2756,6 +2787,14 @@ def onPartialConfig(event):
27562787 y = np .where (y >= 0. ,np .sqrt (y ),- np .sqrt (- y ))
27572788 Plot .plot (x ,y ,pcolor ,picker = False ,label = ph ,linewidth = pwidth ,
27582789 linestyle = pLinStyl )
2790+ if 'PlotDefaults' in data [0 ] and fromTree : # set plot limists from defaults saved with '!'
2791+ #print('setting plot defaults')
2792+ xlim ,ylim ,styleDict = data [0 ]['PlotDefaults' ]
2793+ Page .toolbar .push_current ()
2794+ Plot .set_xlim ((xlim [0 ],xlim [1 ]))
2795+ Plot .set_ylim ((ylim [0 ],ylim [1 ]))
2796+ Page .toolbar .push_current ()
2797+ newPlot = True # prevent carrying limits over from other histograms
27592798 if not newPlot :
27602799 # this restores previous plot limits (but I'm not sure why there are two .push_current calls)
27612800 Page .toolbar .push_current ()
0 commit comments