Belle II Software light-2405-quaxo
Distribution Class Reference
Inheritance diagram for Distribution:
Collaboration diagram for Distribution:

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 578 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 583 of file plotting.py.

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

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 616 of file plotting.py.

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

◆ finish()

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

Reimplemented from Plotter.

Definition at line 663 of file plotting.py.

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

Member Data Documentation

◆ first_binning

first_binning

first binning

Definition at line 612 of file plotting.py.

◆ keep_first_binning

keep_first_binning

Keep first binning if user wants so.

Definition at line 610 of file plotting.py.

◆ normed_to_all_entries

normed_to_all_entries

Normalize histograms before drawing them.

Definition at line 595 of file plotting.py.

◆ normed_to_bin_width

normed_to_bin_width

Normalize histograms before drawing them.

Definition at line 597 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 599 of file plotting.py.

◆ x_axis_label

x_axis_label

x axis label

Definition at line 614 of file plotting.py.

◆ xmax

xmax

size in x/y

Definition at line 608 of file plotting.py.

◆ xmin

xmin

size in x/y

Definition at line 606 of file plotting.py.

◆ ymax

ymax

size in x/y

Definition at line 604 of file plotting.py.

◆ ymin

ymin

size in x/y

Definition at line 602 of file plotting.py.


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