簡體   English   中英

二維直方圖的樣條插值 - Python

[英]Spline Interpolation of a 2D Histogram - Python

我有一個 2D 直方圖(x,y 坐標和“權重”),我需要做一個樣條插值並提取數據(所以不僅僅是圖形),我怎么能用 python 做到這一點? (我在這里附上歷史)謝謝! 光照貼圖 X_Z

你可以使用scipy,我從這里拿了下面的例子並稍微修改了一下:

from scipy import interpolate
import matplotlib.pyplot as plt

# define range of x values
x = np.arange(-5.01, 5.01, 0.25)
# define range of z values
z = np.arange(-5.01, 5.01, 0.25)
# create a meshgrid
xx, zz = np.meshgrid(x, z)
# these weights would be given to you in your histogram - here is an example function to generate weights
weights = np.sin(xx**2+zz**2)
# create interpolation object
f = interpolate.interp2d(x, z, weights, kind='cubic')

# generate new ranges of x and z values
xnew = np.arange(-5.01, 5.01, 1e-2)
znew = np.arange(-5.01, 5.01, 1e-2)
# interpolate 
weightsnew = f(xnew, znew)

# plot
plt.imshow(weightsnew)
plt.show()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM