diff --git a/anesthetic/plot.py b/anesthetic/plot.py index 8c6c40f9..f080ab3a 100644 --- a/anesthetic/plot.py +++ b/anesthetic/plot.py @@ -9,6 +9,7 @@ to create a set of axes and legend proxies. """ +from packaging import version import numpy as np from pandas import Series, DataFrame import matplotlib.pyplot as plt @@ -839,7 +840,11 @@ def fastkde_plot_1d(ax, data, *args, **kwargs): p /= p.max() i = ((x > quantile(x, q[0], p)) & (x < quantile(x, q[-1], p))) - area = np.trapezoid(x=x[i], y=p[i]) if density else 1 + if version.parse(np.__version__) >= version.parse("2.0.0"): + trapezoid = np.trapezoid + else: + trapezoid = np.trapz + area = trapezoid(x=x[i], y=p[i]) if density else 1 if ax.get_xaxis().get_scale() == 'log': x = 10**x ans = ax.plot(x[i], p[i]/area, color=color, *args, **kwargs) @@ -962,7 +967,11 @@ def kde_plot_1d(ax, data, *args, **kwargs): bw = np.sqrt(kde.covariance[0, 0]) pp = cut_and_normalise_gaussian(x, p, bw, xmin=data.min(), xmax=data.max()) pp /= pp.max() - area = np.trapezoid(x=x, y=pp) if density else 1 + if version.parse(np.__version__) >= version.parse("2.0.0"): + trapezoid = np.trapezoid + else: + trapezoid = np.trapz + area = trapezoid(x=x, y=pp) if density else 1 if ax.get_xaxis().get_scale() == 'log': x = 10**x ans = ax.plot(x, pp/area, color=color, *args, **kwargs)