Skip to content

Commit

Permalink
check numpy version for trapz vs trapezoid
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamOrmondroyd committed Sep 12, 2024
1 parent 689ecfb commit bd98396
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions anesthetic/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bd98396

Please sign in to comment.