def gencosine(a, b, C=1): """ Computes generalized cosine of angle between two vectors a and b in subspace spanned by C Parameters ---------- a, b : (N, 1) array_like Input vectors of real or complex element Returns ------- x : scalar Generalized cosine of angle between a and b in subspace of C """ # Validate input if not (isvector(a) and isvector(b)): raise TypeError("Input not a vector") if not C.ndim == 2: raise TypeError("Third argument must be a matrix") nr = np.abs(dot(a.T, dot(C, b)))**2 dr = dot(a.T, dot(C, a)) * dot(b.T, dot(C, b)); x = float(nr)/dr return x
def tallibing(x, y, n, **kwds): ''' TALLIBING Display numbers on field-plot CALL h=tallibing(x,y,n,size,color) x,y = position matrices n = the corresponding matrix of the values to be written (non-integers are rounded) size = font size (optional) (default=8) color = color of text (optional) (default='white') h = column-vector of handles to TEXT objects TALLIBING writes the numbers in a 2D array as text at the positions given by the x and y coordinate matrices. When plotting binned results, the number of datapoints in each bin can be written on the bins in the plot. Example ------- >>> import wafo.graphutil as wg >>> import wafo.demos as wd >>> [x,y,z] = wd.peaks(n=20) >>> h0 = wg.epcolor(x,y,z) >>> h1 = wg.tallibing(x,y,z) pcolor(x,y,z); shading interp; See also -------- text ''' axis = kwds.pop('axis',None) if axis is None: axis = plotbackend.gca() x, y, n = np.atleast_1d(x, y, n) if mlab.isvector(x) or mlab.isvector(y): x, y = np.meshgrid(x,y) x = x.ravel() y = y.ravel() n = n.ravel() n = np.round(n) # delete tallibing object if it exists delete_text_object(_TALLIBING_GID, axis=axis) txtProp = dict(gid=_TALLIBING_GID, size=8, color='w', horizontalalignment='center', verticalalignment='center', fontweight='demi', axes=axis) txtProp.update(**kwds) h = [] for xi,yi, ni in zip(x,y,n): if ni: h.append(axis.text(xi, yi, str(ni), **txtProp)) plotbackend.draw_if_interactive() return h
def isvector(X): """ This function has been moved to matplotlib.mlab -- please import it from there """ warnings.warn('isvector has been moved to matplotlib.mlab -- please import it from there', DeprecationWarning) import matplotlib.mlab as mlab return mlab.isvector( x, y, xi, extrap=extrap )
def isvector(X): """ This function has been moved to matplotlib.mlab -- please import it from there """ # deprecated from cbook in 0.98.4 warnings.warn('isvector has been moved to matplotlib.mlab -- please import it from there', DeprecationWarning) import matplotlib.mlab as mlab return mlab.isvector( x, y, xi, extrap=extrap )
def tallibing(*args, **kwds): ''' TALLIBING Display numbers on field-plot CALL h=tallibing(x,y,n,size,color) Parameters ---------- x, y : array position matrices n : array corresponding matrix of the values to be written (non-integers are rounded) mid_points : bool (default True) data-point-positions are in the middle of bins instead of the corners size : int, (default=8) font size (optional) color : str, (default='white') color of text (optional) Returns ------- h : list handles to TEXT objects TALLIBING writes the numbers in a 2D array as text at the positions given by the x and y coordinate matrices. When plotting binned results, the number of datapoints in each bin can be written on the bins in the plot. Example ------- >>> import wafo.graphutil as wg >>> import wafo.demos as wd >>> [x,y,z] = wd.peaks(n=20) >>> h0 = wg.pcolor(x,y,z) >>> h1 = wg.tallibing(x,y,z) See also -------- text ''' axis = kwds.pop('axis', None) if axis is None: axis = plotbackend.gca() x, y, n = _parse_data(*args, **kwds) if mlab.isvector(x) or mlab.isvector(y): x, y = np.meshgrid(x, y) n = np.round(n) # delete tallibing object if it exists delete_text_object(_TALLIBING_GID, axis=axis) txtProp = dict(gid=_TALLIBING_GID, size=8, color='w', horizontalalignment='center', verticalalignment='center', fontweight='demi', axes=axis) txtProp.update(**kwds) h = [] for xi, yi, ni in zip(x.ravel(), y.ravel(), n.ravel()): if ni: h.append(axis.text(xi, yi, str(ni), **txtProp)) plotbackend.draw_if_interactive() return h