diff --git a/pylot/core/util/pdf.py b/pylot/core/util/pdf.py index 3149fc0a..c3af13e0 100644 --- a/pylot/core/util/pdf.py +++ b/pylot/core/util/pdf.py @@ -157,7 +157,7 @@ class ProbabilityDensityFunction(object): return ProbabilityDensityFunction(x0, incr, npts, pdf) def __nonzero__(self): - return True + return bool(np.round(self.prob_gt_val(self.axis[0]), 4) == 1.) @property def data(self): @@ -259,6 +259,18 @@ class ProbabilityDensityFunction(object): return None return self.data[find_nearest(self.axis, value)] * self.incr + def plot(self): + import matplotlib.pyplot as plt + + plt.plot(self.axis, self.data) + plt.xlabel('x') + plt.ylabel('f(x)') + if self: + plt.title('Probability density function') + else: + plt.title('Function not suitable as probability density function') + plt.show() + def commonlimits(self, incr, other, max_npts=1e5): ''' Takes an increment incr and two left and two right limits and returns