Belle II Software light-2406-ragdoll
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 585 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 590 of file plotting.py.

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

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

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

◆ finish()

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

Reimplemented from Plotter.

Definition at line 670 of file plotting.py.

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

Member Data Documentation

◆ first_binning

first_binning

first binning

Definition at line 619 of file plotting.py.

◆ keep_first_binning

keep_first_binning

Keep first binning if user wants so.

Definition at line 617 of file plotting.py.

◆ normed_to_all_entries

normed_to_all_entries

Normalize histograms before drawing them.

Definition at line 602 of file plotting.py.

◆ normed_to_bin_width

normed_to_bin_width

Normalize histograms before drawing them.

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

◆ x_axis_label

x_axis_label

x axis label

Definition at line 621 of file plotting.py.

◆ xmax

xmax

size in x/y

Definition at line 615 of file plotting.py.

◆ xmin

xmin

size in x/y

Definition at line 613 of file plotting.py.

◆ ymax

ymax

size in x/y

Definition at line 611 of file plotting.py.

◆ ymin

ymin

size in x/y

Definition at line 609 of file plotting.py.


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