当前位置: 首页>>代码示例>>Python>>正文


Python mlab.griddata方法代码示例

本文整理汇总了Python中matplotlib.mlab.griddata方法的典型用法代码示例。如果您正苦于以下问题:Python mlab.griddata方法的具体用法?Python mlab.griddata怎么用?Python mlab.griddata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.mlab的用法示例。


在下文中一共展示了mlab.griddata方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: UpdateData

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import griddata [as 别名]
def UpdateData(self, products, micapsfile):
        self.UpdateExtents(products)

        extents = products.picture.extents
        xmax = extents.xmax
        xmin = extents.xmin
        ymax = extents.ymax
        ymin = extents.ymin

        path = products.map.clipborders[0].path

        if path is not None:
            self.AddPoints(self.x, self.y, self.z, path)

        # self.CreateArray()
        self.X = np.linspace(xmin, xmax, micapsfile.contour.grid[0])
        self.Y = np.linspace(ymin, ymax, micapsfile.contour.grid[1])
        # x = self.data['lon']
        # y = self.data['lat']
        # z = self.data['zvalue']
        self.Z = griddata(self.x, self.y, self.z, self.X, self.Y, 'nn')
        self.X, self.Y = np.meshgrid(self.X, self.Y)

        self.min = min(self.z)
        self.max = max(self.z)
        self.distance = micapsfile.contour.step
        self.min = math.floor(self.min / self.distance) * self.distance
        self.max = math.ceil(self.max / self.distance) * self.distance
        # 如果自定义了legend的最小、最大和步长值 则用自定义的值更新
        self.UpdatePinLegendValue(micapsfile) 
开发者ID:flashlxy,项目名称:PyMICAPS,代码行数:32,代码来源:Micaps3Data.py

示例2: test_griddata_linear

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import griddata [as 别名]
def test_griddata_linear():
    # z is a linear function of x and y.
    def get_z(x, y):
        return 3.0*x - y

    # Passing 1D xi and yi arrays to griddata.
    x = np.asarray([0.0, 1.0, 0.0, 1.0, 0.5])
    y = np.asarray([0.0, 0.0, 1.0, 1.0, 0.5])
    z = get_z(x, y)
    xi = [0.2, 0.4, 0.6, 0.8]
    yi = [0.1, 0.3, 0.7, 0.9]
    zi = mlab.griddata(x, y, z, xi, yi, interp='linear')
    xi, yi = np.meshgrid(xi, yi)
    np.testing.assert_array_almost_equal(zi, get_z(xi, yi))

    # Passing 2D xi and yi arrays to griddata.
    zi = mlab.griddata(x, y, z, xi, yi, interp='linear')
    np.testing.assert_array_almost_equal(zi, get_z(xi, yi))

    # Masking z array.
    z_masked = np.ma.array(z, mask=[False, False, False, True, False])
    correct_zi_masked = np.ma.masked_where(xi + yi > 1.0, get_z(xi, yi))
    zi = mlab.griddata(x, y, z_masked, xi, yi, interp='linear')
    matest.assert_array_almost_equal(zi, correct_zi_masked)
    np.testing.assert_array_equal(np.ma.getmask(zi),
                                  np.ma.getmask(correct_zi_masked)) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:28,代码来源:test_mlab.py

示例3: test_griddata_linear

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import griddata [as 别名]
def test_griddata_linear():
    # z is a linear function of x and y.
    def get_z(x, y):
        return 3.0*x - y

    # Passing 1D xi and yi arrays to griddata.
    x = np.asarray([0.0, 1.0, 0.0, 1.0, 0.5])
    y = np.asarray([0.0, 0.0, 1.0, 1.0, 0.5])
    z = get_z(x, y)
    xi = [0.2, 0.4, 0.6, 0.8]
    yi = [0.1, 0.3, 0.7, 0.9]
    with pytest.warns(MatplotlibDeprecationWarning):
        zi = mlab.griddata(x, y, z, xi, yi, interp='linear')
    xi, yi = np.meshgrid(xi, yi)
    np.testing.assert_array_almost_equal(zi, get_z(xi, yi))

    # Passing 2D xi and yi arrays to griddata.
    with pytest.warns(MatplotlibDeprecationWarning):
        zi = mlab.griddata(x, y, z, xi, yi, interp='linear')
    np.testing.assert_array_almost_equal(zi, get_z(xi, yi))

    # Masking z array.
    z_masked = np.ma.array(z, mask=[False, False, False, True, False])
    correct_zi_masked = np.ma.masked_where(xi + yi > 1.0, get_z(xi, yi))
    with pytest.warns(MatplotlibDeprecationWarning):
        zi = mlab.griddata(x, y, z_masked, xi, yi, interp='linear')
    matest.assert_array_almost_equal(zi, correct_zi_masked)
    np.testing.assert_array_equal(np.ma.getmask(zi),
                                  np.ma.getmask(correct_zi_masked)) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:31,代码来源:test_mlab.py

示例4: nearest_griddata

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import griddata [as 别名]
def nearest_griddata(x, y, z, xi, yi):
    """
    Nearest Neighbor Interpolation Method.

    Nearest-neighbor interpolation (also known as proximal interpolation or, in some contexts, point sampling) is a simple method of multivariate interpolation in one or more dimensions.<br/>

    Interpolation is the problem of approximating the value of a function for a non-given point in some space when given the value of that function in points around (neighboring) that point.<br/>
    The nearest neighbor algorithm selects the value of the nearest point and does not consider the values of neighboring points at all, yielding a piecewise-constant interpolant. <br/>
    The algorithm is very simple to implement and is commonly used (usually along with mipmapping) in real-time 3D rendering to select color values for a textured surface.<br/>

    zi = nearest_griddata(x,y,z,xi,yi) fits a surface of the form z = f*(*x, y) to the data in the (usually) nonuniformly spaced vectors (x, y, z).<br/>
    griddata() interpolates this surface at the points specified by (xi, yi) to produce zi. xi and yi must describe a regular grid.<br/>

    Parameters
    ----------
    x:  array-like
        x-coord [1D array]
    y:  array-like
        y-coord [1D array]
    z:  array-like
        z-coord [1D array]
    xi: array-like
        meshgrid for x-coords [2D array] see <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.html">numpy.meshgrid</a>
    yi: array-like
        meshgrid for y-coords [2D array] see <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.html">numpy.meshgrid</a>

    Returns
    -------
    Interpolated Zi Coord

    zi: array-like
        zi interpolated-value [2D array]  for (xi,yi)
    """
    zi = griddata(zip(x,y), z, (xi, yi), method='nearest')
    return zi 
开发者ID:mmolero,项目名称:pcloudpy,代码行数:37,代码来源:interpolation.py

示例5: test_griddata_nn

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import griddata [as 别名]
def test_griddata_nn():
    # z is a linear function of x and y.
    def get_z(x, y):
        return 3.0*x - y

    # Passing 1D xi and yi arrays to griddata.
    x = np.asarray([0.0, 1.0, 0.0, 1.0, 0.5])
    y = np.asarray([0.0, 0.0, 1.0, 1.0, 0.5])
    z = get_z(x, y)
    xi = [0.2, 0.4, 0.6, 0.8]
    yi = [0.1, 0.3, 0.7, 0.9]
    correct_zi = [[0.49999252, 1.0999978, 1.7000030, 2.3000080],
                  [0.29999208, 0.8999978, 1.5000029, 2.1000059],
                  [-0.1000099, 0.4999943, 1.0999964, 1.6999979],
                  [-0.3000128, 0.2999894, 0.8999913, 1.4999933]]
    zi = mlab.griddata(x, y, z, xi, yi, interp='nn')
    np.testing.assert_array_almost_equal(zi, correct_zi)

    # Decreasing xi or yi should raise ValueError.
    assert_raises(ValueError, mlab.griddata, x, y, z, xi[::-1], yi,
                  interp='nn')
    assert_raises(ValueError, mlab.griddata, x, y, z, xi, yi[::-1],
                  interp='nn')

    # Passing 2D xi and yi arrays to griddata.
    xi, yi = np.meshgrid(xi, yi)
    zi = mlab.griddata(x, y, z, xi, yi, interp='nn')
    np.testing.assert_array_almost_equal(zi, correct_zi)

    # Masking z array.
    z_masked = np.ma.array(z, mask=[False, False, False, True, False])
    correct_zi_masked = np.ma.masked_where(xi + yi > 1.0, correct_zi)
    zi = mlab.griddata(x, y, z_masked, xi, yi, interp='nn')
    np.testing.assert_array_almost_equal(zi, correct_zi_masked, 5)
    np.testing.assert_array_equal(np.ma.getmask(zi),
                                  np.ma.getmask(correct_zi_masked))


#*****************************************************************
# These Tests where taken from SCIPY with some minor modifications
# this can be retreived from:
# https://github.com/scipy/scipy/blob/master/scipy/stats/tests/test_kdeoth.py
#***************************************************************** 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:45,代码来源:test_mlab.py

示例6: test_griddata_nn

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import griddata [as 别名]
def test_griddata_nn():
    pytest.importorskip('mpl_toolkits.natgrid')

    # z is a linear function of x and y.
    def get_z(x, y):
        return 3.0*x - y

    # Passing 1D xi and yi arrays to griddata.
    x = np.asarray([0.0, 1.0, 0.0, 1.0, 0.5])
    y = np.asarray([0.0, 0.0, 1.0, 1.0, 0.5])
    z = get_z(x, y)
    xi = [0.2, 0.4, 0.6, 0.8]
    yi = [0.1, 0.3, 0.7, 0.9]
    correct_zi = [[0.49999252, 1.0999978, 1.7000030, 2.3000080],
                  [0.29999208, 0.8999978, 1.5000029, 2.1000059],
                  [-0.1000099, 0.4999943, 1.0999964, 1.6999979],
                  [-0.3000128, 0.2999894, 0.8999913, 1.4999933]]
    with pytest.warns(MatplotlibDeprecationWarning):
        zi = mlab.griddata(x, y, z, xi, yi, interp='nn')
    np.testing.assert_array_almost_equal(zi, correct_zi, 5)

    with pytest.warns(MatplotlibDeprecationWarning):
        # Decreasing xi or yi should raise ValueError.
        with pytest.raises(ValueError):
            mlab.griddata(x, y, z, xi[::-1], yi, interp='nn')
        with pytest.raises(ValueError):
            mlab.griddata(x, y, z, xi, yi[::-1], interp='nn')

    # Passing 2D xi and yi arrays to griddata.
    xi, yi = np.meshgrid(xi, yi)
    with pytest.warns(MatplotlibDeprecationWarning):
        zi = mlab.griddata(x, y, z, xi, yi, interp='nn')
    np.testing.assert_array_almost_equal(zi, correct_zi, 5)

    # Masking z array.
    z_masked = np.ma.array(z, mask=[False, False, False, True, False])
    correct_zi_masked = np.ma.masked_where(xi + yi > 1.0, correct_zi)
    with pytest.warns(MatplotlibDeprecationWarning):
        zi = mlab.griddata(x, y, z_masked, xi, yi, interp='nn')
    np.testing.assert_array_almost_equal(zi, correct_zi_masked, 5)
    np.testing.assert_array_equal(np.ma.getmask(zi),
                                  np.ma.getmask(correct_zi_masked))


#*****************************************************************
# These Tests where taken from SCIPY with some minor modifications
# this can be retrieved from:
# https://github.com/scipy/scipy/blob/master/scipy/stats/tests/test_kdeoth.py
#***************************************************************** 
开发者ID:holzschu,项目名称:python3_ios,代码行数:51,代码来源:test_mlab.py

示例7: natural_neighbor

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import griddata [as 别名]
def natural_neighbor(x,y,z,xi,yi):
    """
    Natural Neighbor Interpolation Method.

    Natural neighbor interpolation is a method of spatial interpolation, developed by Robin Sibson.
    The method is based on Voronoi tessellation of a discrete set of spatial points.
    This has advantages over simpler methods of interpolation, such as nearest-neighbor interpolation,
    in that it provides a more smooth approximation to the underlying "true" function.
    see <a href="http://en.wikipedia.org/wiki/Radial_basis_function">Radial_basic_function

    zi = natural_neighbor(x,y,z,xi,yi) fits a surface of the form z = f*(*x, y) to the data in the (usually) non uniformly spaced vectors (x, y, z).<br/>
    griddata() interpolates this surface at the points specified by (xi, yi) to produce zi. xi and yi must describe a regular grid.


    Parameters
    ----------

    x:  array-like, shape= 1D
        x-coord [1D array]

    y:  array-like, shape= 1D
        y-coord [1D array]

    z:  array-like, shape= 1D
        z-coord [1D array]

    xi:  array-like, shape= 2D array
        meshgrid for x-coords [2D array]

    yi:  array-like, shape= 2D array
        meshgrid for y-coords [2D array]

    Returns
    -------

    zi: array-like, shape=2D
        zi interpolated-value [2D array]  for (xi,yi)


    """
    zi = mlab.griddata(x,y,z,xi,yi)
    return zi 
开发者ID:mmolero,项目名称:pcloudpy,代码行数:44,代码来源:interpolation.py

示例8: adam_plot

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import griddata [as 别名]
def adam_plot(self, func, obs, hist):
        hist['act'] = np.array(hist['act']).T
        hist['f'] = np.array(hist['f']).T
        hist['g'] = np.array(hist['g']).T
        if self.dimA == 1:
            xs = np.linspace(-1.+1e-8, 1.-1e-8, 100)
            ys = [func(obs[[0],:], [[xi]])[0] for xi in xs]
            fig = plt.figure()
            plt.plot(xs, ys)
            plt.plot(hist['act'][0,0,:], hist['f'][0,:], label='Adam')
            plt.legend()
            fname = os.path.join(FLAGS.outdir, 'adamPlt.png')
            print("Saving Adam plot to {}".format(fname))
            plt.savefig(fname)
            plt.close(fig)
        elif self.dimA == 2:
            assert(False)
        else:
            xs = npr.uniform(-1., 1., (5000, self.dimA))
            ys = np.array([func(obs[[0],:], [xi])[0] for xi in xs])
            epi = np.hstack((xs, ys))
            pca = PCA(n_components=2).fit(epi)
            W = pca.components_[:,:-1]
            xs_proj = xs.dot(W.T)
            fig = plt.figure()

            X = Y = np.linspace(xs_proj.min(), xs_proj.max(), 100)
            Z = griddata(xs_proj[:,0], xs_proj[:,1], ys.ravel(),
                         X, Y, interp='linear')

            plt.contourf(X, Y, Z, 15)
            plt.colorbar()

            adam_x = hist['act'][:,0,:].T
            adam_x = adam_x.dot(W.T)
            plt.plot(adam_x[:,0], adam_x[:,1], label='Adam', color='k')
            plt.legend()

            fname = os.path.join(FLAGS.outdir, 'adamPlt.png')
            print("Saving Adam plot to {}".format(fname))
            plt.savefig(fname)
            plt.close(fig) 
开发者ID:locuslab,项目名称:icnn,代码行数:44,代码来源:icnn.py

示例9: test_griddata_nn

# 需要导入模块: from matplotlib import mlab [as 别名]
# 或者: from matplotlib.mlab import griddata [as 别名]
def test_griddata_nn():
    # z is a linear function of x and y.
    def get_z(x, y):
        return 3.0*x - y

    # Passing 1D xi and yi arrays to griddata.
    x = np.asarray([0.0, 1.0, 0.0, 1.0, 0.5])
    y = np.asarray([0.0, 0.0, 1.0, 1.0, 0.5])
    z = get_z(x, y)
    xi = [0.2, 0.4, 0.6, 0.8]
    yi = [0.1, 0.3, 0.7, 0.9]
    correct_zi = [[0.49999252, 1.0999978, 1.7000030, 2.3000080],
                  [0.29999208, 0.8999978, 1.5000029, 2.1000059],
                  [-0.1000099, 0.4999943, 1.0999964, 1.6999979],
                  [-0.3000128, 0.2999894, 0.8999913, 1.4999933]]
    with pytest.warns(MatplotlibDeprecationWarning):
        zi = mlab.griddata(x, y, z, xi, yi, interp='nn')
    np.testing.assert_array_almost_equal(zi, correct_zi, 5)

    with pytest.warns(MatplotlibDeprecationWarning):
        # Decreasing xi or yi should raise ValueError.
        with pytest.raises(ValueError):
            mlab.griddata(x, y, z, xi[::-1], yi, interp='nn')
        with pytest.raises(ValueError):
            mlab.griddata(x, y, z, xi, yi[::-1], interp='nn')

    # Passing 2D xi and yi arrays to griddata.
    xi, yi = np.meshgrid(xi, yi)
    with pytest.warns(MatplotlibDeprecationWarning):
        zi = mlab.griddata(x, y, z, xi, yi, interp='nn')
    np.testing.assert_array_almost_equal(zi, correct_zi, 5)

    # Masking z array.
    z_masked = np.ma.array(z, mask=[False, False, False, True, False])
    correct_zi_masked = np.ma.masked_where(xi + yi > 1.0, correct_zi)
    with pytest.warns(MatplotlibDeprecationWarning):
        zi = mlab.griddata(x, y, z_masked, xi, yi, interp='nn')
    np.testing.assert_array_almost_equal(zi, correct_zi_masked, 5)
    np.testing.assert_array_equal(np.ma.getmask(zi),
                                  np.ma.getmask(correct_zi_masked))


#*****************************************************************
# These Tests where taken from SCIPY with some minor modifications
# this can be retrieved from:
# https://github.com/scipy/scipy/blob/master/scipy/stats/tests/test_kdeoth.py
#***************************************************************** 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:49,代码来源:test_mlab.py


注:本文中的matplotlib.mlab.griddata方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。