6666Gkchisq = chr (0x03C7 )+ chr (0xb2 )
6767plotDebug = False
6868timeDebug = GSASIIpath .GetConfigValue ('Show_timing' ,False )
69- obsInCaption = True # include the observed, calc,... items in the plot caption (PlotPatterns)
7069# options for publication-quality Rietveld plots
7170plotOpt = {}
71+ plotOpt ['obsInCaption' ] = True # include the observed, calc,... items in the plot caption (PlotPatterns)
7272plotOpt ['labelSize' ] = '11'
7373plotOpt ['dpi' ] = 600
7474plotOpt ['width' ] = 8.
@@ -222,8 +222,8 @@ def OnPlotKeyPress(event):
222222 G2frame .ErrorBars = not G2frame .ErrorBars
223223 elif event .key == 'T' and 'PWDR' in plottype :
224224 Page .plotStyle ['title' ] = not Page .plotStyle .get ('title' ,True )
225- elif event .key == 'f' and 'PWDR' in plottype : # short or full length tick-marks
226- Page .plotStyle ['flTicks' ] = not Page .plotStyle .get ('flTicks' ,False )
225+ elif event .key == 'f' and 'PWDR' in plottype : # short, full length or no tick-marks
226+ Page .plotStyle ['flTicks' ] = ( Page .plotStyle .get ('flTicks' ,0 ) + 1 ) % 3
227227 elif event .key == 'x' and 'PWDR' in plottype :
228228 Page .plotStyle ['exclude' ] = not Page .plotStyle ['exclude' ]
229229 elif event .key == '.' :
@@ -314,11 +314,13 @@ def OnPlotKeyPress(event):
314314 Page .plotStyle ['Offset' ][1 ] -= 1.
315315 elif event .key == 'r' and not G2frame .SinglePlot :
316316 Page .plotStyle ['Offset' ][1 ] += 1.
317- elif event .key == 'o' :
318- if G2frame .SinglePlot and not G2frame .Contour :
319- global obsInCaption # include the observed, calc,... items in the plot caption (PlotPatterns)
320- obsInCaption = not obsInCaption
321- elif not G2frame .SinglePlot :
317+ elif event .key == 'o' : # controls caption
318+ if G2frame .Contour : return
319+ # include the observed, calc,... items in the plot caption (PlotPatterns)
320+ plotOpt ['obsInCaption' ] = not plotOpt ['obsInCaption' ]
321+ elif event .key in ['O' ,'shift+o' ]: # resets offsets
322+ if G2frame .Contour : return
323+ if not G2frame .SinglePlot : # waterfall: reset the offsets
322324 G2frame .Cmax = 1.0
323325 G2frame .Cmin = 0.0
324326 Page .plotStyle ['Offset' ] = [0 ,0 ]
@@ -411,7 +413,8 @@ def OnPlotKeyPress(event):
411413 Page .plotStyle ['chanPlot' ] = False
412414 elif event .key == 'm' :
413415 if not G2frame .Contour :
414- G2frame .SinglePlot = not G2frame .SinglePlot
416+ G2frame .SinglePlot = not G2frame .SinglePlot
417+ if not G2frame .SinglePlot : plotOpt ['obsInCaption' ] = False # remove caption from waterfall
415418 G2frame .Contour = False
416419 newPlot = True
417420 elif event .key == 'F' and not G2frame .SinglePlot :
@@ -430,7 +433,11 @@ def OnPlotKeyPress(event):
430433 dlg .Destroy ()
431434 newPlot = True
432435 elif event .key in ['+' ,'=' ,'shift+=' ]: # assumes US keyboard
433- G2frame .plusPlot = (G2frame .plusPlot + 1 )% 3
436+ if G2frame .Contour : return
437+ if G2frame .SinglePlot :
438+ G2frame .plusPlot = (G2frame .plusPlot + 1 )% 3
439+ else :
440+ G2frame .plusPlot = (G2frame .plusPlot + 1 )% 4
434441 elif event .key == '/' :
435442 Page .plotStyle ['Normalize' ] = not Page .plotStyle ['Normalize' ]
436443 newPlot = True
@@ -1488,7 +1495,7 @@ def incCptn(string):
14881495 '''Adds a underscore to "hide" a MPL object from the legend if
14891496 obsInCaption is False
14901497 '''
1491- if obsInCaption :
1498+ if plotOpt [ ' obsInCaption' ] :
14921499 return string
14931500 else :
14941501 return '_' + string
@@ -1664,7 +1671,7 @@ def onPartialConfig(event):
16641671 except :
16651672 G2frame .UseLimits = {i :[False ,False ] for i in ('xlims' ,'ylims' ,'dylims' ,'cylims' )}
16661673 #=====================================================================================
1667- # code to setup for plotting Rietveld results. Turns off multiplot,
1674+ # code to setup for plotting Rietveld results. Turns off multiplot (contour/waterfall) ,
16681675 # sqrtplot, turn on + and weight plot, but sqrtPlot qPlot and dPlot are not changed.
16691676 # Magnification regions are ignored.
16701677 # the last-plotted histogram (from G2frame.PatternId) is used for this plotting
@@ -1825,10 +1832,15 @@ def onPartialConfig(event):
18251832 'f: toggle full-length ticks' ,'g: toggle grid' ,
18261833 'X: toggle cumulative chi^2' ,
18271834 'm: toggle multidata plot' ,'n: toggle log(I)' ,]
1828- if obsInCaption :
1829- Page .Choice += ['o: remove obs, calc,... from legend' ,]
1835+ if plotOpt ['obsInCaption' ]:
1836+ addrem = 'remove'
1837+ else :
1838+ addrem = 'add'
1839+ if G2frame .SinglePlot :
1840+ what = "obs, calc,..."
18301841 else :
1831- Page .Choice += ['o: add obs, calc,... to legend' ,]
1842+ what = "histogram names"
1843+ Page .Choice += [f'o: legend: { addrem } { what } in legend' ,]
18321844 if ifLimits :
18331845 Page .Choice += ['e: create excluded region' ,
18341846 's: toggle sqrt plot' ,'w: toggle (Io-Ic)/sig plot' ,
@@ -1850,7 +1862,7 @@ def onPartialConfig(event):
18501862 if not G2frame .SinglePlot :
18511863 Page .Choice = Page .Choice + \
18521864 ['u/U: offset up/10x' ,'d/D: offset down/10x' ,'l: offset left' ,'r: offset right' ,
1853- 'o : reset offset' ,'F: select data' ,'/: normalize' ]
1865+ 'O : reset offset' ,'F: select data' ,'/: normalize' ]
18541866 else :
18551867 Page .Choice = Page .Choice + ['p: toggle partials (if available)' ,]
18561868 if G2frame .SinglePlot :
@@ -2106,11 +2118,13 @@ def onPartialConfig(event):
21062118 if G2frame .Contour :
21072119 xye0 = xye [0 ] # drop mask for contouring
21082120
2109- # convert all X values and then reapply mask
2121+ # convert all X values and then reapply mask if xye0 is a masked array
2122+ mask = None
2123+ if hasattr (xye0 ,'mask' ): mask = xye0 .mask
21102124 if Page .plotStyle ['qPlot' ] and 'PWDR' in plottype and not ifLimits :
2111- X = ma .array (2. * np .pi / G2lat .Pos2dsp (Parms ,xye0 .data ),mask = xye0 . mask )
2125+ X = ma .array (2. * np .pi / G2lat .Pos2dsp (Parms ,xye0 .data ),mask = mask )
21122126 elif Page .plotStyle ['dPlot' ] and 'PWDR' in plottype and not ifLimits :
2113- X = ma .array (G2lat .Pos2dsp (Parms ,xye0 .data ),mask = xye0 . mask )
2127+ X = ma .array (G2lat .Pos2dsp (Parms ,xye0 .data ),mask = mask )
21142128 else :
21152129 X = copy .deepcopy (xye0 )
21162130 if ifpicked and not G2frame .Contour :
@@ -2251,6 +2265,9 @@ def onPartialConfig(event):
22512265 elif G2frame .plusPlot == 1 :
22522266 pP = '+'
22532267 lW = 0
2268+ elif G2frame .plusPlot == 2 :
2269+ pP = ''
2270+ lW = 1.5
22542271 else :
22552272 pP = '+'
22562273 lW = 1.5
@@ -2352,7 +2369,7 @@ def onPartialConfig(event):
23522369 Plot .set_yscale ("log" ,nonpositive = 'mask' )
23532370 Plot .plot (X ,Y ,marker = pP ,color = pwdrCol ['Obs_color' ],linewidth = lW ,picker = True ,pickradius = 3. ,
23542371 clip_on = Clip_on ,label = incCptn ('obs' ))
2355- if G2frame .SinglePlot or G2frame .plusPlot :
2372+ if G2frame .SinglePlot or G2frame .plusPlot == 1 or G2frame . plusPlot == 2 :
23562373 Plot .plot (X ,Z ,pwdrCol ['Calc_color' ],picker = False ,label = incCptn ('calc' ),linewidth = 1.5 )
23572374 if G2frame .plusPlot :
23582375 Plot .plot (X ,W ,pwdrCol ['Bkg_color' ],picker = False ,label = incCptn ('bkg' ),linewidth = 1.5 ) #background
@@ -2394,9 +2411,16 @@ def onPartialConfig(event):
23942411 Plot .plot (X ,ZB ,pwdrCol ['Bkg_color' ],picker = False ,label = incCptn ('calc' ),linewidth = 1.5 )
23952412 else :
23962413 if 'PWDR' in plottype :
2397- ObsLine = Plot .plot (Xum ,Y / ymax ,color = pwdrCol ['Obs_color' ],marker = pP ,linewidth = lW ,
2398- picker = True ,pickradius = 3. ,clip_on = Clip_on ,label = incCptn ('obs' )) #Io
2399- CalcLine = Plot .plot (X ,Z / ymax ,pwdrCol ['Calc_color' ],picker = False ,label = incCptn ('calc' ),linewidth = 1.5 ) #Ic
2414+ if G2frame .plusPlot != 3 :
2415+ ObsLine = Plot .plot (Xum ,Y / ymax ,color = pwdrCol ['Obs_color' ],marker = pP ,linewidth = lW ,
2416+ picker = True ,pickradius = 3. ,clip_on = Clip_on ,label = incCptn ('obs' )) #Io
2417+ CalcLine = Plot .plot (X ,Z / ymax ,pwdrCol ['Calc_color' ],
2418+ picker = False ,label = incCptn ('calc' ),linewidth = 1.5 ) #Ic
2419+ else : # waterfall mode=3: plot 1st pattern like others, name in legend?
2420+ name = Pattern [2 ]
2421+ if Pattern [0 ]['histTitle' ]: name = Pattern [0 ]['histTitle' ]
2422+ ObsLine = Plot .plot (Xum ,Y / ymax ,color = pwdrCol ['Obs_color' ],marker = pP ,linewidth = 1.5 ,
2423+ picker = True ,pickradius = 3. ,clip_on = Clip_on ,label = incCptn (name )) #Io
24002424 else :
24012425 Plot .plot (X ,YB ,color = pwdrCol ['Obs_color' ],marker = pP ,linewidth = lW ,
24022426 picker = True ,pickradius = 3. ,clip_on = Clip_on ,label = incCptn ('obs' ))
@@ -2513,7 +2537,10 @@ def onPartialConfig(event):
25132537 picker = False ,nonpositive = 'mask' )
25142538 else :
25152539 if 'PWDR' in plottype :
2516- Plot .plot (X ,Y / ymax ,color = mcolors .cmap (icolor ),picker = False )
2540+ # waterfall mode=3: name in legend?
2541+ name = Pattern [2 ]
2542+ if Pattern [0 ]['histTitle' ]: name = Pattern [0 ]['histTitle' ]
2543+ Plot .plot (X ,Y / ymax ,color = mcolors .cmap (icolor ),picker = False ,label = incCptn (name ))
25172544 elif plottype in ['SASD' ,'REFD' ]:
25182545 try :
25192546 Plot .loglog (X ,Y ,mcolors .cmap (icolor ),
@@ -2662,13 +2689,13 @@ def onPartialConfig(event):
26622689 xtick = peak .T [0 ]
26632690 else :
26642691 xtick = peak .T [1 ]
2665- if not Page .plotStyle .get ('flTicks' ,False ) : # short tick-marks
2692+ if Page .plotStyle .get ('flTicks' ,0 ) == 0 : # short tick-marks
26662693 Page .tickDict [phase ],_ = Plot .plot (
26672694 xtick ,pos ,'|' ,mew = w ,ms = l ,picker = True ,pickradius = 3. ,
26682695 label = phase ,color = plcolor )
26692696 # N.B. above creates two Line2D objects, 2nd is ignored.
26702697 # Not sure what each does.
2671- else : # full length tick-marks
2698+ elif Page . plotStyle . get ( 'flTicks' , 0 ) == 1 : # full length tick-marks
26722699 if len (xtick ) > 0 :
26732700 # create an ~hidden tickmark to create a legend entry
26742701 Page .tickDict [phase ] = Plot .plot (xtick [0 ],0 ,'|' ,mew = 0.5 ,ms = l ,
@@ -2682,10 +2709,13 @@ def onPartialConfig(event):
26822709 labels = dict (zip (legends ,handles )) # remove duplicate phase entries
26832710 handles = [labels [item ] for item in labels ]
26842711 legends = list (labels .keys ())
2685- if len (Phases ) and obsInCaption :
2686- Plot .legend (handles ,legends ,title = 'Phases & Data' ,loc = 'best' )
2712+ if len (Phases ) and plotOpt ['obsInCaption' ] and Page .plotStyle .get ('flTicks' ,0 ) != 2 :
2713+ msg = 'Data'
2714+ elif len (Phases ) and plotOpt ['obsInCaption' ]:
2715+ msg = 'Phases & Data'
26872716 else :
2688- Plot .legend (handles ,legends ,title = 'Data' ,loc = 'best' )
2717+ msg = 'Phases'
2718+ Plot .legend (handles ,legends ,title = msg ,loc = 'best' )
26892719
26902720 if G2frame .Contour :
26912721 time0 = time .time ()
0 commit comments