@@ -413,7 +413,7 @@ def empty_data2D(qx, qy=None, resolution=0.0):
413413 return data
414414
415415
416- def plot_data (data , view = None , limits = None ):
416+ def plot_data (data , view = None , limits = None , index = None ):
417417 # type: (Data, str, OptLimits) -> None
418418 """
419419 Plot data loaded by the sasview loader.
@@ -431,13 +431,13 @@ def plot_data(data, view=None, limits=None):
431431 if hasattr (data , 'isSesans' ) and data .isSesans :
432432 _plot_result_sesans (data , None , None , view , use_data = True , limits = limits )
433433 elif hasattr (data , 'qx_data' ) and not getattr (data , 'radial' , False ):
434- _plot_result2D (data , None , None , view , use_data = True , limits = limits )
434+ _plot_result2D (data , None , None , view , use_data = True , limits = limits , index = index )
435435 else :
436- _plot_result1D (data , None , None , view , use_data = True , limits = limits )
436+ _plot_result1D (data , None , None , view , use_data = True , limits = limits , index = index )
437437
438438
439439def plot_theory (data , theory , resid = None , view = None , use_data = True ,
440- limits = None , Iq_calc = None ):
440+ limits = None , Iq_calc = None , index = None ):
441441 # type: (Data, OptArray, OptArray, OptString, bool, OptLimits, OptArray) -> None
442442 """
443443 Plot theory calculation.
@@ -461,10 +461,10 @@ def plot_theory(data, theory, resid=None, view=None, use_data=True,
461461 if hasattr (data , 'isSesans' ) and data .isSesans :
462462 _plot_result_sesans (data , theory , resid , view , use_data = True , limits = limits )
463463 elif hasattr (data , 'qx_data' ) and not getattr (data , 'radial' , False ):
464- _plot_result2D (data , theory , resid , view , use_data , limits = limits )
464+ _plot_result2D (data , theory , resid , view , use_data , limits = limits , index = index )
465465 else :
466466 _plot_result1D (data , theory , resid , view , use_data ,
467- limits = limits , Iq_calc = Iq_calc )
467+ limits = limits , Iq_calc = Iq_calc , index = index )
468468
469469
470470def protect (func ):
@@ -490,7 +490,7 @@ def wrapper(*args, **kw):
490490
491491@protect
492492def _plot_result1D (data , theory , resid , view , use_data ,
493- limits = None , Iq_calc = None ):
493+ limits = None , Iq_calc = None , index = None ):
494494 # type: (Data1D, OptArray, OptArray, str, bool, OptLimits, OptArray) -> None
495495 """
496496 Plot the data and residuals for 1D data.
@@ -515,6 +515,9 @@ def _plot_result1D(data, theory, resid, view, use_data,
515515
516516 scale = 1e8 * data .x ** 4 if view == 'q4' else 1.0
517517
518+ if index is None :
519+ index = slice (None )
520+
518521 if use_data or use_theory :
519522 if num_plots > 1 :
520523 plt .subplot (1 , num_plots , 1 )
@@ -538,8 +541,8 @@ def _plot_result1D(data, theory, resid, view, use_data,
538541 # Note: masks merge, so any masked theory points will stay masked,
539542 # and the data mask will be added to it.
540543 #mtheory = masked_array(theory, data.mask.copy())
541- theory_x = data .x [data . mask == 0 ]
542- theory_scale = scale if np .isscalar (scale ) else scale [data . mask == 0 ]
544+ theory_x = data .x [index ]
545+ theory_scale = scale if np .isscalar (scale ) else scale [index ]
543546 mtheory = masked_array (theory )
544547 mtheory [~ np .isfinite (mtheory )] = masked
545548 if view == 'log' :
@@ -573,7 +576,7 @@ def _plot_result1D(data, theory, resid, view, use_data,
573576 #plt.axis('equal')
574577
575578 if use_resid :
576- theory_x = data .x [data . mask == 0 ]
579+ theory_x = data .x [index ]
577580 mresid = masked_array (resid )
578581 mresid [~ np .isfinite (mresid )] = masked
579582 some_present = (mresid .count () > 0 )
@@ -641,7 +644,7 @@ def _plot_result_sesans(data, theory, resid, view, use_data, limits=None):
641644
642645
643646@protect
644- def _plot_result2D (data , theory , resid , view , use_data , limits = None ):
647+ def _plot_result2D (data , theory , resid , view , use_data , limits = None , index = None ):
645648 # type: (Data2D, OptArray, OptArray, str, bool, OptLimits) -> None
646649 """
647650 Plot the data and residuals for 2D data.
@@ -653,12 +656,15 @@ def _plot_result2D(data, theory, resid, view, use_data, limits=None):
653656 use_theory = theory is not None
654657 use_resid = resid is not None
655658 num_plots = use_data + use_theory + use_resid
659+ mask = ~ data .mask
660+ if index is None :
661+ index = mask
656662
657663 # Put theory and data on a common colormap scale
658664 vmin , vmax = np .inf , - np .inf
659665 target = None # type: OptArray
660666 if use_data :
661- target = data .data [~ data . mask ]
667+ target = data .data [mask ] # full data
662668 datamin = target [target > 0 ].min () if view == 'log' else target .min ()
663669 datamax = target .max ()
664670 vmin = min (vmin , datamin )
@@ -677,7 +683,7 @@ def _plot_result2D(data, theory, resid, view, use_data, limits=None):
677683 if use_data :
678684 if num_plots > 1 :
679685 plt .subplot (1 , num_plots , 1 )
680- _plot_2d_signal (data , target , view = view , vmin = vmin , vmax = vmax )
686+ _plot_2d_signal (data , target , view = view , vmin = vmin , vmax = vmax , index = mask )
681687 plt .title ('data' )
682688 h = plt .colorbar ()
683689 h .set_label ('$I(q)$' )
@@ -686,7 +692,7 @@ def _plot_result2D(data, theory, resid, view, use_data, limits=None):
686692 if use_theory :
687693 if num_plots > 1 :
688694 plt .subplot (1 , num_plots , use_data + 1 )
689- _plot_2d_signal (data , theory , view = view , vmin = vmin , vmax = vmax )
695+ _plot_2d_signal (data , theory , view = view , vmin = vmin , vmax = vmax , index = index )
690696 plt .title ('theory' )
691697 h = plt .colorbar ()
692698 h .set_label (r'$\log_{10}I(q)$' if view == 'log'
@@ -697,14 +703,14 @@ def _plot_result2D(data, theory, resid, view, use_data, limits=None):
697703 if use_resid :
698704 if num_plots > 1 :
699705 plt .subplot (1 , num_plots , use_data + use_theory + 1 )
700- _plot_2d_signal (data , resid , view = 'linear' )
706+ _plot_2d_signal (data , resid , view = 'linear' , index = index )
701707 plt .title ('residuals' )
702708 h = plt .colorbar ()
703709 h .set_label (r'$\Delta I(q)$' )
704710
705711
706712@protect
707- def _plot_2d_signal (data , signal , vmin = None , vmax = None , view = None ):
713+ def _plot_2d_signal (data , signal , vmin = None , vmax = None , view = None , index = None ):
708714 # type: (Data2D, np.ndarray, Optional[float], Optional[float], str) -> tuple[float, float]
709715 """
710716 Plot the target value for the data. This could be the data itself,
@@ -719,8 +725,8 @@ def _plot_2d_signal(data, signal, vmin=None, vmax=None, view=None):
719725 view = 'log'
720726
721727 image = np .zeros_like (data .qx_data )
722- image [~ data . mask ] = signal
723- valid = np .isfinite (image ) & ~ data . mask
728+ image [index ] = signal
729+ valid = np .isfinite (image ) & index
724730 if view == 'log' :
725731 valid &= image > 0
726732 if vmin is None :
0 commit comments