Belle II Software development
Distribution Class Reference
Inheritance diagram for Distribution:
Plotter

Public Member Functions

def __init__ (self, figure=None, axis=None, normed_to_all_entries=False, normed_to_bin_width=False, keep_first_binning=False, range_in_std=None)
 
def add (self, data, column, mask=None, weight_column=None, label=None)
 
def finish (self)
 

Public Attributes

 normed_to_all_entries
 Normalize histograms before drawing them.
 
 normed_to_bin_width
 Normalize histograms before drawing them.
 
 range_in_std
 Show only a certain range in terms of standard deviations of the data.
 
 ymin
 size in x/y
 
 ymax
 size in x/y
 
 xmin
 size in x/y
 
 xmax
 size in x/y
 
 keep_first_binning
 Keep first binning if user wants so.
 
 first_binning
 first binning
 
 x_axis_label
 x axis label
 

Detailed Description

Plots distribution of a quantity

Definition at line 584 of file plotting.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  figure = None,
  axis = None,
  normed_to_all_entries = False,
  normed_to_bin_width = False,
  keep_first_binning = False,
  range_in_std = None 
)
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 true if histograms should be normed before drawing
@param keep_first_binning use the binning of the first distribution for further plots
@param range_in_std show only the data in a windows around +- range_in_std * standard_deviation around the mean

Reimplemented from Plotter.

Definition at line 589 of file plotting.py.

590 keep_first_binning=False, range_in_std=None):
591 """
592 Creates a new figure and axis if None is given, sets the default plot parameters
593 @param figure default draw figure which is used
594 @param axis default draw axis which is used
595 @param normed true if histograms should be normed before drawing
596 @param keep_first_binning use the binning of the first distribution for further plots
597 @param range_in_std show only the data in a windows around +- range_in_std * standard_deviation around the mean
598 """
599 super().__init__(figure, axis)
600
601 self.normed_to_all_entries = normed_to_all_entries
602
603 self.normed_to_bin_width = normed_to_bin_width
604
605 self.range_in_std = range_in_std
606 # if self.normed_to_all_entries or self.normed_to_bin_width:
607
608 self.ymin = float(0)
609
610 self.ymax = float('-inf')
611
612 self.xmin = float('inf')
613
614 self.xmax = float('-inf')
615
616 self.keep_first_binning = keep_first_binning
617
618 self.first_binning = None
619
620 self.x_axis_label = ''
621

Member Function Documentation

◆ add()

def add (   self,
  data,
  column,
  mask = None,
  weight_column = None,
  label = None 
)
Add a new distribution to the plots
@param data pandas.DataFrame containing all data
@param column which is used to calculate distribution histogram
@param mask boolean numpy.array defining which events are used for the histogram
@param weight_column column in data containing the weights for each event

Reimplemented from Plotter.

Definition at line 622 of file plotting.py.

622 def add(self, data, column, mask=None, weight_column=None, label=None):
623 """
624 Add a new distribution to the plots
625 @param data pandas.DataFrame containing all data
626 @param column which is used to calculate distribution histogram
627 @param mask boolean numpy.array defining which events are used for the histogram
628 @param weight_column column in data containing the weights for each event
629 """
630 if mask is None:
631 mask = numpy.ones(len(data)).astype('bool')
632
633 bins = 100
634 if self.keep_first_binning and self.first_binning is not None:
635 bins = self.first_binning
636 hists = histogram.Histograms(data, column, {'Total': mask}, weight_column=weight_column,
637 bins=bins, equal_frequency=False, range_in_std=self.range_in_std)
638 if self.keep_first_binning and self.first_binning is None:
639 self.first_binning = hists.bins
640 hist, hist_error = hists.get_hist('Total')
641
642 if self.normed_to_all_entries:
643 normalization = float(numpy.sum(hist))
644 hist = hist / normalization
645 hist_error = hist_error / normalization
646
647 if self.normed_to_bin_width:
648 hist = hist / hists.bin_widths
649 hist_error = hist_error / hists.bin_widths
650
651 self.xmin, self.xmax = min(hists.bin_centers.min(), self.xmin), max(hists.bin_centers.max(), self.xmax)
652 self.ymin = numpy.nanmin([hist.min(), self.ymin])
653 self.ymax = numpy.nanmax([(hist + hist_error).max(), self.ymax])
654
655 p = self._plot_datapoints(self.axis, hists.bin_centers, hist, xerr=hists.bin_widths / 2, yerr=hist_error)
656 self.plots.append(p)
657 self.x_axis_label = column
658
659 appendix = ''
660 if self.ymax <= self.ymin or self.xmax <= self.xmin:
661 appendix = ' No data to plot!'
662
663 if label is None:
664 self.labels.append(column + appendix)
665 else:
666 self.labels.append(label + appendix)
667 return self
668

◆ finish()

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

Reimplemented from Plotter.

Definition at line 669 of file plotting.py.

669 def finish(self):
670 """
671 Sets limits, title, axis-labels and legend of the plot
672 """
673 self.axis.set_title("Distribution Plot")
674 self.axis.get_xaxis().set_label_text(self.x_axis_label)
675
676 self.axis.legend([x[0] for x in self.plots], self.labels, loc='best', fancybox=True, framealpha=0.5)
677
678 if self.ymax <= self.ymin or self.xmax <= self.xmin:
679 self.axis.set_xlim((0., 1.))
680 self.axis.set_ylim((0., 1.))
681 self.axis.text(0.36, 0.5, 'No data to plot', fontsize=60, color='black')
682 return self
683
684 self.scale_limits()
685
686 self.axis.set_xlim((self.xmin, self.xmax))
687 self.axis.set_ylim((self.ymin, self.ymax))
688
689 if self.normed_to_all_entries and self.normed_to_bin_width:
690 self.axis.get_yaxis().set_label_text('# Entries per Bin / (# Entries * Bin Width)')
691 elif self.normed_to_all_entries:
692 self.axis.get_yaxis().set_label_text('# Entries per Bin / # Entries')
693 elif self.normed_to_bin_width:
694 self.axis.get_yaxis().set_label_text('# Entries per Bin / Bin Width')
695 else:
696 self.axis.get_yaxis().set_label_text('# Entries per Bin')
697
698 return self
699
700

Member Data Documentation

◆ first_binning

first_binning

first binning

Definition at line 618 of file plotting.py.

◆ keep_first_binning

keep_first_binning

Keep first binning if user wants so.

Definition at line 616 of file plotting.py.

◆ normed_to_all_entries

normed_to_all_entries

Normalize histograms before drawing them.

Definition at line 601 of file plotting.py.

◆ normed_to_bin_width

normed_to_bin_width

Normalize histograms before drawing them.

Definition at line 603 of file plotting.py.

◆ range_in_std

range_in_std

Show only a certain range in terms of standard deviations of the data.

Definition at line 605 of file plotting.py.

◆ x_axis_label

x_axis_label

x axis label

Definition at line 620 of file plotting.py.

◆ xmax

xmax

size in x/y

Definition at line 614 of file plotting.py.

◆ xmin

xmin

size in x/y

Definition at line 612 of file plotting.py.

◆ ymax

ymax

size in x/y

Definition at line 610 of file plotting.py.

◆ ymin

ymin

size in x/y

Definition at line 608 of file plotting.py.


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