示例#1
0
def meshgrid(x,y):
    """
    For vectors x, y with lengths Nx=len(x) and Ny=len(y), return X, Y
    where X and Y are (Ny, Nx) shaped arrays with the elements of x
    and y repeated to fill the matrix

    EG,

      [X, Y] = meshgrid([1,2,3], [4,5,6,7])

       X =
         1   2   3
         1   2   3
         1   2   3
         1   2   3


       Y =
         4   4   4
         5   5   5
         6   6   6
         7   7   7
  """
  
    x = array(x)
    y = array(y)
    numRows, numCols = len(y), len(x)  # yes, reversed
    x.shape = 1, numCols
    X = repeat(x, numRows)

    y.shape = numRows,1
    Y = repeat(y, numCols, 1)
    return X, Y
示例#2
0
def get_xyz_where(Z, Cond):
    """
    Z and Cond are MxN matrices.  Z are data and Cond is a boolean
    matrix where some condition is satisfied.  Return value is x,y,z
    where x and y are the indices into Z and z are the values of Z at
    those indices.  x,y,z are 1D arrays
    """

    M, N = Z.shape
    z = ravel(Z)
    ind = nonzero(ravel(Cond))

    x = arange(M)
    x.shape = M, 1
    X = repeat(x, N, 1)
    x = ravel(X)

    y = arange(N)
    y.shape = 1, N
    Y = repeat(y, M)
    y = ravel(Y)

    x = take(x, ind)
    y = take(y, ind)
    z = take(z, ind)
    return x, y, z
示例#3
0
def meshgrid(x, y):
    """
    For vectors x, y with lengths Nx=len(x) and Ny=len(y), return X, Y
    where X and Y are (Ny, Nx) shaped arrays with the elements of x
    and y repeated to fill the matrix

    EG,

      [X, Y] = meshgrid([1,2,3], [4,5,6,7])

       X =
         1   2   3
         1   2   3
         1   2   3
         1   2   3


       Y =
         4   4   4
         5   5   5
         6   6   6
         7   7   7
  """

    x = array(x)
    y = array(y)
    numRows, numCols = len(y), len(x)  # yes, reversed
    x.shape = 1, numCols
    X = repeat(x, numRows)

    y.shape = numRows, 1
    Y = repeat(y, numCols, 1)
    return X, Y
示例#4
0
 def set_data(self, x, y, A):
     x = asarray(x).astype(Float32)
     y = asarray(y).astype(Float32)
     A = asarray(A)
     if len(x.shape) != 1 or len(y.shape) != 1\
        or A.shape[0:2] != (y.shape[0], x.shape[0]):
         raise TypeError("Axes don't match array shape")
     if len(A.shape) not in [2, 3]:
         raise TypeError("Can only plot 2D or 3D data")
     if len(A.shape) == 3 and A.shape[2] not in [1, 3, 4]:
         raise TypeError(
             "3D arrays must have three (RGB) or four (RGBA) color components"
         )
     if len(A.shape) == 3 and A.shape[2] == 1:
         A.shape = A.shape[0:2]
     if len(A.shape) == 2:
         if typecode(A) != UInt8:
             A = (self.cmap(self.norm(A)) * 255).astype(UInt8)
         else:
             A = repeat(A[:, :, NewAxis], 4, 2)
             A[:, :, 3] = 255
     else:
         if typecode(A) != UInt8:
             A = (255 * A).astype(UInt8)
         if A.shape[2] == 3:
             B = zeros(tuple(list(A.shape[0:2]) + [4]), UInt8)
             B[:, :, 0:3] = A
             B[:, :, 3] = 255
             A = B
     self._A = A
     self._Ax = x
     self._Ay = y
     self._imcache = None
示例#5
0
 def set_data(self, x, y, A):
     x = asarray(x).astype(Float32)
     y = asarray(y).astype(Float32)
     A = asarray(A)
     if len(x.shape) != 1 or len(y.shape) != 1\
        or A.shape[0:2] != (y.shape[0], x.shape[0]):
         raise TypeError("Axes don't match array shape")
     if len(A.shape) not in [2, 3]:
         raise TypeError("Can only plot 2D or 3D data")
     if len(A.shape) == 3 and A.shape[2] not in [1, 3, 4]:
         raise TypeError("3D arrays must have three (RGB) or four (RGBA) color components")
     if len(A.shape) == 3 and A.shape[2] == 1:
          A.shape = A.shape[0:2]
     if len(A.shape) == 2:
         if typecode(A) != UInt8:
             A = (self.cmap(self.norm(A))*255).astype(UInt8)
         else:
             A = repeat(A[:,:,NewAxis], 4, 2)
             A[:,:,3] = 255
     else:
         if typecode(A) != UInt8:
             A = (255*A).astype(UInt8)
         if A.shape[2] == 3:
             B = zeros(tuple(list(A.shape[0:2]) + [4]), UInt8)
             B[:,:,0:3] = A
             B[:,:,3] = 255
             A = B
     self._A = A
     self._Ax = x
     self._Ay = y
     self._imcache = None
示例#6
0
def get_xyz_where(Z, Cond):
    """
    Z and Cond are MxN matrices.  Z are data and Cond is a boolean
    matrix where some condition is satisfied.  Return value is x,y,z
    where x and y are the indices into Z and z are the values of Z at
    those indices.  x,y,z are 1D arrays
    """
    
    M,N = Z.shape
    z = ravel(Z)
    ind = nonzero( ravel(Cond) )

    x = arange(M); x.shape = M,1
    X = repeat(x, N, 1)
    x = ravel(X)

    y = arange(N); y.shape = 1,N
    Y = repeat(y, M)
    y = ravel(Y)

    x = take(x, ind)
    y = take(y, ind)
    z = take(z, ind)
    return x,y,z