我正在尝试检查该功能LinearNDInterpolator
在以下Python代码中调用
from scipy.interpolate.interpnd import LinearNDInterpolator
我想运行一个调用函数的Python脚本LinearNDInterpolator
并设置一个断点,例如函数第304行LinearNDInterpolator https://github.com/scipy/scipy/blob/193f160feeeb6256d26ba7d42c627910bc78d4a5/scipy/interpolate/interpnd.pyx#L304。我怎样才能做到这一点?
我正在使用 PyCharm。我无法“步入”代码LinearNDInterpolator
。以下是我正在运行的示例脚本。
import numpy as np
from scipy.interpolate.interpnd import LinearNDInterpolator
import matplotlib.pyplot as plt
x = np.linspace(-1,1,100)
y = np.linspace(-1,1,100)
X, Y = np.meshgrid(x,y)
def f(x, y):
s = np.hypot(x, y)
phi = np.arctan2(y, x)
tau = s + s*(1-s)/5 * np.sin(6*phi)
return 5*(1-tau) + tau
T = f(X, Y)
# Choose npts random point from the discrete domain of our model function
npts = 400
px, py = np.random.choice(x, npts), np.random.choice(y, npts)
fig, ax = plt.subplots(nrows=2, ncols=2)
# Plot the model function and the randomly selected sample points
ax[0,0].contourf(X, Y, T)
ax[0,0].scatter(px, py, c='k', alpha=0.2, marker='.')
ax[0,0].set_title('Sample points on f(X,Y)')
# Interpolate using three different methods and plot
i = 0
method = 'linear'
#for i, method in enumerate(('nearest', 'linear', 'cubic')):
ip = LinearNDInterpolator((px, py), f(px,py))
Ti = ip((X, Y))
r, c = (i+1) // 2, (i+1) % 2
ax[r,c].contourf(X, Y, Ti)
ax[r,c].set_title('method = {}'.format(method))
plt.show()