1

!私は(x、y、z)の形式の値を持っています。list_plot3dプロットを作成することにより、それらが完全に等間隔ではないことがはっきりとわかります。それらは通常、xy平面上に3〜5ポイントの小さな「ブロブ」を形成します。したがって、補間と最終的な「等高線」プロットをより良くするために、またはより滑らかに(?)と言うべきであるために、データのブロブが何らかの形であるように、長方形のグリッド(チェス盤の正方形のような)を作成する必要がありますか?滑らかに」?これは一部の人にとっては些細なことかもしれませんが、私はこれを初めて試し、少し苦労しています。私はscipy.interplate.interp2dのようなscipyパッケージを見てきましたが、最後に作成されたグラフは本当に悪いです。たぶん、私のようなアマチュアのためのsagemathの2D補間に関する簡単なチュートリアルですか?いくつかのアドバイス?ありがとうございました。

編集:

https://docs.google.com/file/d/0Bxv8ab9PeMQVUFhBYWlldU9ib0E/edit?pli=1

これは主に、このメッセージとともに生成される種類のグラフです。

Warning:     No more knots can be added because the number of B-spline
coefficients
    already exceeds the number of data points m. Probably causes:
either
    s or m too small. (fp>s)
    kx,ky=3,3 nx,ny=17,20 m=200 fp=4696.972223 s=0.000000

このグラフを取得するには、次のコマンドを実行します。

f_interpolation = scipy.interpolate.interp2d(*zip(*matrix(C)),kind='cubic')
               plot_interpolation = contour_plot(lambda x,y:
                   f_interpolation(x,y)[0], (22.419,22.439),(37.06,37.08) ,cmap='jet', contours=numpy.arange(0,1400,100), colorbar=True)

               plot_all = plot_interpolation

               plot_all.show(axes_labels=["m", "m"])

ここで、matrix(c)は、10000 x 3のような巨大なマトリックス、または1000000 x 3のようなさらに多くのマトリックスになる可能性があります。matrix(C)がわずか200 x 3であった現在添付した画像のように、データが少なくても、グラフの不良の問題は解決しません。だから私は、プログラムの不具合の可能性は別として、このコマンドの使用方法が完全に間違っている可能性があると考え始めました。したがって、グリッドの使用についてアドバイスを求める理由は、「私のデータをコマンドにスローします。

4

1 に答える 1

3

scipy.interpolate.interp2d 関数を使用して同様の問題が発生しました。私の理解では、interp1d/interp2d および関連する関数が基礎となる計算に FITPACK の古いラッピングを使用するために問題が発生するということです。FITPACKの新しいラッピングに依存するスプライン関数を使用して、あなたと同様の問題を解決することができました。スプライン関数は、 http://docs.scipy.org/doc/scipy/reference/interpolate.htmlの名前にすべて大文字が含まれているように見えるため、識別できます。scipy インストール内では、これらの新しい関数は scipy/interpolate/fitpack2.py にあるように見えますが、古いラッピングを使用する関数は fitpack.py にあります。

あなたの目的のために、 RectBivariateSpline はあなたが望むものです。RectBivariateSpline を実装するためのサンプル コードを次に示します。

import numpy as np
from scipy import interpolate

# Generate unevenly spaced x/y data for axes
npoints = 25
maxaxis = 100
x = (np.random.rand(npoints)*maxaxis) - maxaxis/2.
y = (np.random.rand(npoints)*maxaxis) - maxaxis/2.
xsort = np.sort(x)
ysort = np.sort(y)

# Generate the z-data, which first requires converting
# x/y data into grids
xg, yg = np.meshgrid(xsort,ysort)
z = xg**2 - yg**2

# Generate the interpolated, evenly spaced data
# Note that the min/max of x/y isn't necessarily 0 and 100 since
# randomly chosen points were used. If we want to avoid extrapolation,
# the explicit min/max must be found
interppoints = 100
xinterp = np.linspace(xsort[0],xsort[-1],interppoints)
yinterp = np.linspace(ysort[0],ysort[-1],interppoints)

# Generate the kernel that will be used for interpolation
# Note that the default version uses three coefficients for
# interpolation (i.e. parabolic, a*x**2 + b*x +c). Higher order
# interpolation can be used by setting kx and ky to larger 
# integers, i.e. interpolate.RectBivariateSpline(xsort,ysort,z,kx=5,ky=5)
kernel = interpolate.RectBivariateSpline(xsort,ysort,z)

# Now calculate the linear, interpolated data
zinterp = kernel(xinterp, yinterp)
于 2012-07-16T15:17:51.470 に答える