如何用不规则比例插值曲线?

2024-09-30 04:32:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的粒度数据,我想在图表上显示,其中x是粒度,y是概率密度函数。x遵循一个几何序列(每个值乘以2)

x:[0.0,0.0781300000000000005,0.1562600000000001,0.31252000000000002,0.625040000000040004,1.25008000000001,2500800000000002,5.00032000000000003,10.000640000000001,20.001280000000001]

y:[0.0,1.0512499897262986,0.876497322043381,0.6221799472771921,0.3760124741123981,0.19346808043817057,0.08474951460350254,0.0316071940839253,0.010035880788326037,0.0]

下面是图表:

enter image description here

我一直在试着像Excel一样平滑曲线。我试过使用interp1d(所有方法)、spline、akima1dipolator。在


Tags: 数据方法图表粒度序列excel曲线spline
1条回答
网友
1楼 · 发布于 2024-09-30 04:32:24

所以在我上面的评论中,我很容易地说。然而,问题在于,数据最终非常平淡。三次插值和高阶插值不喜欢平面数据。它们倾向于振荡。正如@f5r5e5d所提到的,诀窍是重新缩放数据,使扁平部分变得非常短。在这种情况下,双对数刻度似乎可以。不幸的是,这不适用于y = 0值。对于一个小的点,选择一个小的偏移值,或者选择一个不太小的值。在

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d

xList = [0.078130000000000005, 0.15626000000000001, 0.31252000000000002, 0.62504000000000004, 1.2500800000000001, 2.5001600000000002, 5.0003200000000003, 10.000640000000001, 20.001280000000001]

yList = [ 1.0512499897262986, 0.8764973224043381, 0.6221799472771921, 0.3760124741123981, 0.19346808043817057, 0.08474951460350254, 0.0316071940839253, 0.010035880788326037, 0.0]

yList[-1] = 1.e-5 ###manually put a value for the zero

xLogList = [ np.log( x ) for x in xList ]
yLogList = [ np.log( y ) for y in yList ]
f = interp1d(xLogList, yLogList, kind='cubic')
xInterLogList = np.linspace( np.log( xList[0] ), np.log( xList[-1] ), 100 )
yInterLogList = [ f( x ) for x in xInterLogList ]

fig1=plt.figure()
ax=fig1.add_subplot( 1, 1, 1 )

ax.plot(xList, yList)
ax.plot( [ np.exp( x ) for x in xInterLogList  ], [ np.exp( y ) for y in yInterLogList ] )

plt.show()  

Interpolation 蓝色表示原始数据,橙色表示平滑插值。在

相关问题 更多 >

    热门问题