Belle II Software light-2406-ragdoll
Difference Class Reference
Inheritance diagram for Difference:
Collaboration diagram for Difference:

Public Member Functions

def __init__ (self, figure=None, axis=None, normed=False, shift_to_zero=False)
 
def add (self, data, column, minuend_mask, subtrahend_mask, weight_column=None, label=None)
 
def finish (self, line_color='black')
 

Public Attributes

 normed
 Minuend and subtrahend are normed before comparing them if this is true.
 
 shift_to_zero
 Mean difference is shifted to zero (removes constant offset) if this is true.
 
 ymin
 min y value
 
 ymax
 Maximum y value.
 
 xmax
 Maximum x value.
 
 x_axis_label
 Label on x axis.
 

Detailed Description

Plots the difference between two histograms

Definition at line 769 of file plotting.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  figure = None,
  axis = None,
  normed = False,
  shift_to_zero = False 
)
Creates a new figure and axis if None is given, sets the default plot parameters
@param figure default draw figure which is used
@param axis default draw axis which is used
@param normed normalize minuend and subtrahend before comparing them
@param shift_to_zero mean difference is shifted to zero, to remove constant offset due to e.g. different sample sizes

Reimplemented from Plotter.

Definition at line 786 of file plotting.py.

786 def __init__(self, figure=None, axis=None, normed=False, shift_to_zero=False):
787 """
788 Creates a new figure and axis if None is given, sets the default plot parameters
789 @param figure default draw figure which is used
790 @param axis default draw axis which is used
791 @param normed normalize minuend and subtrahend before comparing them
792 @param shift_to_zero mean difference is shifted to zero, to remove constant offset due to e.g. different sample sizes
793 """
794 super().__init__(figure, axis)
795 self.normed = normed
796 self.shift_to_zero = shift_to_zero
797 if self.normed:
798 self.ymin = -0.01
799 self.ymax = 0.01
800 else:
801 self.ymin = -1
802 self.ymax = 1
803

Member Function Documentation

◆ add()

def add (   self,
  data,
  column,
  minuend_mask,
  subtrahend_mask,
  weight_column = None,
  label = None 
)
Add a new difference plot
@param data pandas.DataFrame containing all data
@param column which is used to calculate distribution histogram
@param minuend_mask boolean numpy.array defining which events are for the minuend histogram
@param subtrahend_mask boolean numpy.array defining which events are for the subtrahend histogram
@param weight_column column in data containing the weights for each event
@param label label for the legend if None, the column name is used

Reimplemented from Plotter.

Definition at line 804 of file plotting.py.

804 def add(self, data, column, minuend_mask, subtrahend_mask, weight_column=None, label=None):
805 """
806 Add a new difference plot
807 @param data pandas.DataFrame containing all data
808 @param column which is used to calculate distribution histogram
809 @param minuend_mask boolean numpy.array defining which events are for the minuend histogram
810 @param subtrahend_mask boolean numpy.array defining which events are for the subtrahend histogram
811 @param weight_column column in data containing the weights for each event
812 @param label label for the legend if None, the column name is used
813 """
814 hists = histogram.Histograms(data, column, {'Minuend': minuend_mask, 'Subtrahend': subtrahend_mask},
815 weight_column=weight_column, equal_frequency=False)
816 minuend, minuend_error = hists.get_hist('Minuend')
817 subtrahend, subtrahend_error = hists.get_hist('Subtrahend')
818
819 difference_error = histogram.poisson_error(minuend + subtrahend)
820 if self.normed:
821 difference_error = difference_error / (numpy.sum(minuend) + numpy.sum(subtrahend))
822 minuend = minuend / numpy.sum(minuend)
823 subtrahend = subtrahend / numpy.sum(subtrahend)
824 difference = minuend - subtrahend
825
826 if self.shift_to_zero:
827 difference = difference - numpy.mean(difference)
828
829 self.xmin, self.xmax = min(hists.bin_centers.min(), self.xmin), max(hists.bin_centers.max(), self.xmax)
830 self.ymin = min((difference - difference_error).min(), self.ymin)
831 self.ymax = max((difference + difference_error).max(), self.ymax)
832
833 p = self._plot_datapoints(self.axis, hists.bin_centers, difference, xerr=hists.bin_widths / 2, yerr=difference_error)
834 self.plots.append(p)
835 if label is None:
836 self.labels.append(label)
837 else:
838 self.labels.append(column)
839 self.x_axis_label = column
840 return self
841
def poisson_error(n_tot)
Definition: histogram.py:24

◆ finish()

def finish (   self,
  line_color = 'black' 
)
Sets limits, title, axis-labels and legend of the plot

Reimplemented from Plotter.

Definition at line 842 of file plotting.py.

842 def finish(self, line_color='black'):
843 """
844 Sets limits, title, axis-labels and legend of the plot
845 """
846 self.axis.plot((self.xmin, self.xmax), (0, 0), color=line_color, linewidth=4, rasterized=True)
847 self.scale_limits()
848 self.axis.set_xlim((self.xmin, self.xmax))
849 self.axis.set_ylim((self.ymin, self.ymax))
850 self.axis.set_title("Difference Plot")
851 self.axis.get_yaxis().set_major_locator(matplotlib.ticker.MaxNLocator(5))
852 self.axis.get_xaxis().set_label_text(self.x_axis_label)
853 self.axis.get_yaxis().set_label_text('Difference')
854 self.axis.legend([x[0] for x in self.plots], self.labels, loc='best', fancybox=True, framealpha=0.5)
855 return self
856
857
Definition: plot.py:1

Member Data Documentation

◆ normed

normed

Minuend and subtrahend are normed before comparing them if this is true.

Definition at line 795 of file plotting.py.

◆ shift_to_zero

shift_to_zero

Mean difference is shifted to zero (removes constant offset) if this is true.

Definition at line 796 of file plotting.py.

◆ x_axis_label

x_axis_label

Label on x axis.

Definition at line 839 of file plotting.py.

◆ xmax

xmax

Maximum x value.

Definition at line 829 of file plotting.py.

◆ ymax

ymax

Maximum y value.

Definition at line 799 of file plotting.py.

◆ ymin

ymin

min y value

Definition at line 798 of file plotting.py.


The documentation for this class was generated from the following file: