Belle II Software development
ProfilePlot Class Reference

Public Member Functions

def __init__ (self, x, y, x_axis=None, n_bins=None, label=None)
 
def draw (self, color='black')
 

Public Attributes

 x_axis
 Binning in x.
 
 mean
 Mean of y in bin x.
 
 err
 Std of Mean y in bin x.
 
 label
 Matplotlib label for the plot.
 

Detailed Description

 Basic Profile plot

Creates the profile Histogram from x and y distrinbutions
It plots mean(y) in bins of x

Attributes:
    x_axis (array)  : Binning in x
    mean (array)    : Mean of y in bin x
    err (array)     : Std of Mean y in bin x
    label (string)  : Matplotlib label for the plot

Definition at line 131 of file tools.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  x,
  y,
  x_axis = None,
  n_bins = None,
  label = None 
)
 init function
:param x:       Distribution in x
:param y:       Distribution in y
:param n_bins:  (optional) n bins in x, is set automatically if not provided
:param x_axis:  binning for the x-axis
:param label:   Matplotlib label for the plot

Definition at line 145 of file tools.py.

145 def __init__(self, x, y, x_axis=None, n_bins=None, label=None):
146 """ init function
147 :param x: Distribution in x
148 :param y: Distribution in y
149 :param n_bins: (optional) n bins in x, is set automatically if not provided
150 :param x_axis: binning for the x-axis
151 :param label: Matplotlib label for the plot
152 """
153 if x_axis is None:
154 x_axis = transform.get_optimal_bin_size(len(x))
155 if n_bins is not None:
156 x_axis = n_bins
157
158
159 _, self.x_axis = np.histogram(x, x_axis)
160
161
162 self.mean = []
163
164
165 self.err = []
166
167
168 self.label = label
169
170 # Calculating the Profile histogram
171 for last_x, next_x in zip(self.x_axis[:-1], self.x_axis[1:]):
172 bin_range = (x > last_x) & (x < next_x)
173 n_y_in_bin = len(y[bin_range])
174 if n_y_in_bin == 0:
175 self.mean.append(0)
176 self.err.append(0)
177 else:
178 self.mean.append(np.mean(y[bin_range]))
179 self.err.append(np.sqrt(np.var(y[bin_range]) / n_y_in_bin))
180

Member Function Documentation

◆ draw()

def draw (   self,
  color = 'black' 
)
 Draw function
:param color: matplotlib color

Definition at line 181 of file tools.py.

181 def draw(self, color='black'):
182 """ Draw function
183 :param color: matplotlib color
184 """
185 bin_centers = (self.x_axis[1:] + self.x_axis[:-1]) / 2.0
186 plt.errorbar(bin_centers, self.mean, color=color, yerr=self.err,
187 linewidth=2, ecolor=color, label=self.label, fmt='.')
188
189

Member Data Documentation

◆ err

err

Std of Mean y in bin x.

Definition at line 165 of file tools.py.

◆ label

label

Matplotlib label for the plot.

Definition at line 168 of file tools.py.

◆ mean

mean

Mean of y in bin x.

Definition at line 162 of file tools.py.

◆ x_axis

x_axis

Binning in x.

Definition at line 159 of file tools.py.


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