对数刻度上的插值

时间:2012-05-10 14:35:24

标签: python numpy matplotlib scipy interpolation

我想插入一些数据,并在对数刻度(pyplot.loglog)上绘制结果。问题是得到的插值看起来很奇怪,并且在对数刻度上绘制时显示不连续性。插入日志缩放数据的最佳方法是什么?

pyplot.loglog(x, y, '+')
pyplot.hold(True)
s = scipy.interpolate.InterpolatedUnivariateSpline(x, y)
xs = numpy.logspace(numpy.log10(numpy.min(x)), numpy.log10(numpy.max(x)))
pyplot.loglog(xs, s(xs)) # This looks very strange because of the log scale!

实际上,我通过插入数据的日志来成功实现它,但我想知道是否有更简单的方法来实现相同的结果?

pyplot.loglog(x, y, '+')
pyplot.hold(True)
s = scipy.interpolate.InterpolatedUnivariateSpline(numpy.log10(x), numpy.log10(y))
xs = numpy.logspace(numpy.log10(numpy.min(x)), numpy.log10(numpy.max(x)))
pyplot.loglog(xs, numpy.power(10, s(numpy.log10(xs)))

1 个答案:

答案 0 :(得分:4)

看起来首先采用数据的对数,然后拟合是执行此操作的常规方法。请参阅Fitting a Power Law Distribution