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
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