【问题标题】:Spline Interpolation of a 2D Histogram - Python二维直方图的样条插值 - Python
【发布时间】:2021-12-06 08:17:53
【问题描述】:

我有一个 2D 直方图(x,y 坐标和“权重”),我需要进行样条插值并提取数据(所以不仅仅是图形),我如何用 python 做到这一点? (我在这里附上历史)谢谢! LightMap X_Z

【问题讨论】:

    标签: python matplotlib scipy histogram spline


    【解决方案1】:

    你可以使用scipy,我从here中拿了下面的例子,稍作修改:

    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()
    

    【讨论】:

    • 谢谢,但我不太了解如何使用该示例。如何使用我的 z、x 坐标和权重数据集?
    • 我编辑了我的答案
    • 非常感谢!
    猜你喜欢
    • 2020-08-25
    • 1970-01-01
    • 2013-05-25
    • 1970-01-01
    • 1970-01-01
    • 2019-06-02
    • 2020-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多