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
def _get_plottable(self): # If log scale is set, only pos data will be returned x, y = self._x, self._y try: logx = self._transform.get_funcx().get_type()==LOG10 except RuntimeError: logx = False # non-separable try: logy = self._transform.get_funcy().get_type()==LOG10 except RuntimeError: logy = False # non-separable if not logx and not logy: return x, y if self._logcache is not None: waslogx, waslogy, xcache, ycache = self._logcache if logx==waslogx and waslogy==logy: return xcache, ycache Nx = len(x) Ny = len(y) if logx: indx = greater(x, 0) else: indx = ones(len(x)) if logy: indy = greater(y, 0) else: indy = ones(len(y)) ind = nonzero(logical_and(indx, indy)) x = take(x, ind) y = take(y, ind) self._logcache = logx, logy, x, y return x, y
def __call__(self, X, alpha=1.0): """ X is either a scalar or an array (of any dimension). If scalar, a tuple of rgba values is returned, otherwise an array with the new shape = oldshape+(4,). Any values that are outside the 0,1 interval are clipped to that interval before generating rgb values. Alpha must be a scalar """ if not self._isinit: self._init() alpha = min(alpha, 1.0) # alpha must be between 0 and 1 alpha = max(alpha, 0.0) if type(X) in [IntType, FloatType]: vtype = 'scalar' xa = array([X]) else: vtype = 'array' xa = asarray(X) # assume the data is properly normalized #xa = where(xa>1.,1.,xa) #xa = where(xa<0.,0.,xa) xa = (xa *(self.N-1)).astype(Int) rgba = zeros(xa.shape+(4,), Float) rgba[...,0] = take(self._red_lut, xa) rgba[...,1] = take(self._green_lut, xa) rgba[...,2] = take(self._blue_lut, xa) rgba[...,3] = alpha if vtype == 'scalar': rgba = tuple(rgba[0,:]) return rgba
def __call__(self, X, alpha=1.0): """ X is either a scalar or an array (of any dimension). If scalar, a tuple of rgba values is returned, otherwise an array with the new shape = oldshape+(4,). Any values that are outside the 0,1 interval are clipped to that interval before generating rgb values. Alpha must be a scalar """ alpha = min(alpha, 1.0) # alpha must be between 0 and 1 alpha = max(alpha, 0.0) if type(X) in [IntType, FloatType]: vtype = 'scalar' xa = array([X]) else: vtype = 'array' xa = array(X) xa = where(xa>1.,1.,xa) xa = where(xa<0.,0.,xa) xa = (xa *(self.N-1)).astype(Int) rgba = zeros(xa.shape+(4,), Float) rgba[...,0] = take(self._red_lut, xa) rgba[...,1] = take(self._green_lut, xa) rgba[...,2] = take(self._blue_lut, xa) rgba[...,3] = alpha if vtype == 'scalar': rgba = tuple(rgba[0,:]) return rgba
def _set_clip(self): if not self._useDataClipping: return #self._logcache = None try: self._xmin, self._xmax except AttributeError: indx = arange(len(self._x)) else: if not hasattr(self, '_xsorted'): self._xsorted = self._is_sorted(self._x) if len(self._x) == 1: indx = [0] elif self._xsorted: # for really long signals, if we know they are sorted # on x we can save a lot of time using search sorted # since the alternative approach requires 3 O(len(x) ) ops indMin, indMax = searchsorted(self._x, array([self._xmin, self._xmax])) indMin = max(0, indMin - 1) indMax = min(indMax + 1, len(self._x)) skip = 0 if self._lod: # if level of detail is on, decimate the data # based on pixel width raise NotImplementedError('LOD deprecated') l, b, w, h = self.get_window_extent().get_bounds() skip = int((indMax - indMin) / w) if skip > 0: indx = arange(indMin, indMax, skip) else: indx = arange(indMin, indMax) else: indx = nonzero( logical_and(self._x >= self._xmin, self._x <= self._xmax)) self._xc = take(self._x, indx) self._yc = take(self._y, indx) # y data clipping for connected lines can introduce horizontal # line artifacts near the clip region. If you really need y # clipping for efficiency, consider using plot(y,x) instead. if (self._yc.shape == self._xc.shape and self._linestyle is None): try: self._ymin, self._ymax except AttributeError: indy = arange(len(self._yc)) else: indy = nonzero( logical_and(self._yc >= self._ymin, self._yc <= self._ymax)) else: indy = arange(len(self._yc)) self._xc = take(self._xc, indy) self._yc = take(self._yc, indy)
def _set_clip(self): if not self._useDataClipping: return # self._logcache = None try: self._xmin, self._xmax except AttributeError: indx = arange(len(self._x)) else: if not hasattr(self, "_xsorted"): self._xsorted = self._is_sorted(self._x) if len(self._x) == 1: indx = [0] elif self._xsorted: # for really long signals, if we know they are sorted # on x we can save a lot of time using search sorted # since the alternative approach requires 3 O(len(x) ) ops indMin, indMax = searchsorted(self._x, array([self._xmin, self._xmax])) indMin = max(0, indMin - 1) indMax = min(indMax + 1, len(self._x)) skip = 0 if self._lod: # if level of detail is on, decimate the data # based on pixel width raise NotImplementedError("LOD deprecated") l, b, w, h = self.get_window_extent().get_bounds() skip = int((indMax - indMin) / w) if skip > 0: indx = arange(indMin, indMax, skip) else: indx = arange(indMin, indMax) else: indx = nonzero(logical_and(self._x >= self._xmin, self._x <= self._xmax)) self._xc = take(self._x, indx) self._yc = take(self._y, indx) # y data clipping for connected lines can introduce horizontal # line artifacts near the clip region. If you really need y # clipping for efficiency, consider using plot(y,x) instead. if self._yc.shape == self._xc.shape and self._linestyle is None: try: self._ymin, self._ymax except AttributeError: indy = arange(len(self._yc)) else: indy = nonzero(logical_and(self._yc >= self._ymin, self._yc <= self._ymax)) else: indy = arange(len(self._yc)) self._xc = take(self._xc, indy) self._yc = take(self._yc, indy)
def _get_numeric_clipped_data_in_range(self): # if the x or y clip is set, only plot the points in the # clipping region. If log scale is set, only pos data will be # returned try: self._xc, self._yc except AttributeError: x, y = self._x, self._y else: x, y = self._xc, self._yc try: logx = self._transform.get_funcx().get_type() == LOG10 except RuntimeError: logx = False # non-separable try: logy = self._transform.get_funcy().get_type() == LOG10 except RuntimeError: logy = False # non-separable if not logx and not logy: return x, y if self._logcache is not None: waslogx, waslogy, xcache, ycache = self._logcache if logx == waslogx and waslogy == logy: return xcache, ycache Nx = len(x) Ny = len(y) if logx: indx = greater(x, 0) else: indx = ones(len(x)) if logy: indy = greater(y, 0) else: indy = ones(len(y)) ind = nonzero(logical_and(indx, indy)) x = take(x, ind) y = take(y, ind) self._logcache = logx, logy, x, y return x, y
def orth(A): """ Orthogonalization procedure by Matlab. The description is taken from its help: Q = ORTH(A) is an orthonormal basis for the range of A. That is, Q'*Q = I, the columns of Q span the same space as the columns of A, and the number of columns of Q is the rank of A. """ A = numerix.array(A) U,S,V = MLab.svd(A) m,n = numerix.shape(A) if m > 1: s = S elif m == 1: s = S[0] else: s = 0 tol = MLab.max((m,n)) * MLab.max(s) * _eps_approx r = MLab.sum(s > tol) Q = numerix.take(U,range(r),1) return Q
def __call__(self): 'Return the locations of the ticks' self.verify_intervals() b=self._base vmin, vmax = self.viewInterval.get_bounds() vmin = math.log(vmin)/math.log(b) vmax = math.log(vmax)/math.log(b) if vmax<vmin: vmin, vmax = vmax, vmin ticklocs = [] numdec = math.floor(vmax)-math.ceil(vmin) if self._subs is None: # autosub if numdec>10: subs = array([1.0]) elif numdec>6: subs = arange(2.0, b, 2.0) else: subs = arange(2.0, b) else: subs = self._subs for decadeStart in b**arange(math.floor(vmin),math.ceil(vmax)): ticklocs.extend( subs*decadeStart ) if(len(subs) and subs[0]==1.0): ticklocs.append(b**math.ceil(vmax)) ticklocs = array(ticklocs) ind = nonzero(logical_and(ticklocs>=b**vmin , ticklocs<=b**vmax)) ticklocs = take(ticklocs,ind) return ticklocs
def entropy(y, bins): """ Return the entropy of the data in y \sum p_i log2(p_i) where p_i is the probability of observing y in the ith bin of bins. bins can be a number of bins or a range of bins; see hist Compare S with analytic calculation for a Gaussian x = mu + sigma*randn(200000) Sanalytic = 0.5 * ( 1.0 + log(2*pi*sigma**2.0) ) """ n,bins = hist(y, bins) n = n.astype(Float) n = take(n, nonzero(n)) # get the positive p = divide(n, len(y)) delta = bins[1]-bins[0] S = -1.0*asum(p*log(p)) + log(delta) #S = -1.0*asum(p*log(p)) return S
def __call__(self): 'Return the locations of the ticks' self.verify_intervals() b=self.base subs=self.subs vmin, vmax = self.viewInterval.get_bounds() vmin = math.log(vmin)/math.log(b) vmax = math.log(vmax)/math.log(b) if vmax<vmin: vmin, vmax = vmax, vmin ticklocs = [] for decadeStart in b**arange(math.floor(vmin),math.ceil(vmax)): ticklocs.extend( subs*decadeStart ) if(len(subs) and subs[0]==1.0): ticklocs.append(b**math.ceil(vmax)) ticklocs = array(ticklocs) ind = nonzero(logical_and(ticklocs>=b**vmin , ticklocs<=b**vmax)) ticklocs = take(ticklocs,ind) return ticklocs
def entropy(y, bins): """ Return the entropy of the data in y \sum p_i log2(p_i) where p_i is the probability of observing y in the ith bin of bins. bins can be a number of bins or a range of bins; see hist Compare S with analytic calculation for a Gaussian x = mu + sigma*randn(200000) Sanalytic = 0.5 * ( 1.0 + log(2*pi*sigma**2.0) ) """ n, bins = hist(y, bins) n = n.astype(Float) n = take(n, nonzero(n)) # get the positive p = divide(n, len(y)) delta = bins[1] - bins[0] S = -1.0 * asum(p * log(p)) + log(delta) #S = -1.0*asum(p*log(p)) return S
def orth(A): """ Orthogonalization procedure by Matlab. The description is taken from its help: Q = ORTH(A) is an orthonormal basis for the range of A. That is, Q'*Q = I, the columns of Q span the same space as the columns of A, and the number of columns of Q is the rank of A. """ A = array(A) U,S,V = numerix.mlab.svd(A) m,n = numerix.shape(A) if m > 1: s = S elif m == 1: s = S[0] else: s = 0 tol = numerix.mlab.max((m,n)) * numerix.mlab.max(s) * _eps_approx r = asum(s > tol) Q = take(U,range(r),1) return Q
def levypdf(x, gamma, alpha): "Returm the levy pdf evaluated at x for params gamma, alpha" N = len(x) if N % 2 != 0: raise ValueError, 'x must be an event length array; try\n' + \ 'x = linspace(minx, maxx, N), where N is even' dx = x[1] - x[0] f = 1 / (N * dx) * arange(-N / 2, N / 2, Float) ind = concatenate([arange(N / 2, N, Int), arange(N / 2, Int)]) df = f[1] - f[0] cfl = exp(-gamma * absolute(2 * pi * f)**alpha) px = fft(take(cfl, ind) * df).astype(Float) return take(px, ind)
def longest_contiguous_ones(x): """ return the indicies of the longest stretch of contiguous ones in x, assuming x is a vector of zeros and ones. """ if len(x)==0: return array([]) ind = find(x==0) if len(ind)==0: return arange(len(x)) if len(ind)==len(x): return array([]) y = zeros( (len(x)+2,), x.typecode()) y[1:-1] = x dif = diff(y) up = find(dif == 1); dn = find(dif == -1); ind = find( dn-up == max(dn - up)) ind = arange(take(up, ind), take(dn, ind)) return ind
def longest_contiguous_ones(x): """ return the indicies of the longest stretch of contiguous ones in x, assuming x is a vector of zeros and ones. """ if len(x) == 0: return array([]) ind = find(x == 0) if len(ind) == 0: return arange(len(x)) if len(ind) == len(x): return array([]) y = zeros((len(x) + 2, ), typecode(x)) y[1:-1] = x dif = diff(y) up = find(dif == 1) dn = find(dif == -1) ind = find(dn - up == max(dn - up)) ind = arange(take(up, ind), take(dn, ind)) return ind
def levypdf(x, gamma, alpha): "Returm the levy pdf evaluated at x for params gamma, alpha" N = len(x) if N%2 != 0: raise ValueError, 'x must be an event length array; try\n' + \ 'x = linspace(minx, maxx, N), where N is even' dx = x[1]-x[0] f = 1/(N*dx)*arange(-N/2, N/2, Float) ind = concatenate([arange(N/2, N, Int), arange(N/2,Int)]) df = f[1]-f[0] cfl = exp(-gamma*absolute(2*pi*f)**alpha) px = fft(take(cfl,ind)*df).astype(Float) return take(px, ind)
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
def prctile(x, p = (0.0, 25.0, 50.0, 75.0, 100.0)): """ Return the percentiles of x. p can either be a sequence of percentil values or a scalar. If p is a sequence the i-th element of the return sequence is the p(i)-th percentile of x """ x = sort(ravel(x)) Nx = len(x) if not iterable(p): return x[int(p*Nx/100.0)] p = multiply(array(p), Nx/100.0) ind = p.astype(Int) ind = where(ind>=Nx, Nx-1, ind) return take(x, ind)
def prctile(x, p=(0.0, 25.0, 50.0, 75.0, 100.0)): """ Return the percentiles of x. p can either be a sequence of percentil values or a scalar. If p is a sequence the i-th element of the return sequence is the p(i)-th percentile of x """ x = sort(ravel(x)) Nx = len(x) if not iterable(p): return x[int(p * Nx / 100.0)] p = multiply(array(p), Nx / 100.0) ind = p.astype(Int) ind = where(ind >= Nx, Nx - 1, ind) return take(x, ind)
def makeMappingArray(N, data): """Create an N-element 1-d lookup table data represented by a list of x,y0,y1 mapping correspondences. Each element in this list represents how a value between 0 and 1 (inclusive) represented by x is mapped to a corresponding value between 0 and 1 (inclusive). The two values of y are to allow for discontinuous mapping functions (say as might be found in a sawtooth) where y0 represents the value of y for values of x <= to that given, and y1 is the value to be used for x > than that given). The list must start with x=0, end with x=1, and all values of x must be in increasing order. Values between the given mapping points are determined by simple linear interpolation. The function returns an array "result" where result[x*(N-1)] gives the closest value for values of x between 0 and 1. """ try: adata = array(data) except: raise TypeError("data must be convertable to an array") shape = adata.shape if len(shape) != 2 and shape[1] != 3: raise ValueError("data must be nx3 format") x = adata[:,0] y0 = adata[:,1] y1 = adata[:,2] if x[0] != 0. or x[-1] != 1.0: raise ValueError( "data mapping points must start with x=0. and end with x=1") if sometrue(sort(x)-x): raise ValueError( "data mapping points must have x in increasing order") # begin generation of lookup table x = x * (N-1) lut = zeros((N,), Float) xind = arange(float(N)) ind = searchsorted(x, xind)[1:-1] lut[1:-1] = ( divide(xind[1:-1] - take(x,ind-1), take(x,ind)-take(x,ind-1) ) *(take(y0,ind)-take(y1,ind-1)) + take(y1,ind-1)) lut[0] = y1[0] lut[-1] = y0[-1] # ensure that the lut is confined to values between 0 and 1 by clipping it clip(lut, 0.0, 1.0) #lut = where(lut > 1., 1., lut) #lut = where(lut < 0., 0., lut) return lut
def makeMappingArray(N, data): """Create an N-element 1-d lookup table data represented by a list of x,y0,y1 mapping correspondences. Each element in this list represents how a value between 0 and 1 (inclusive) represented by x is mapped to a corresponding value between 0 and 1 (inclusive). The two values of y are to allow for discontinuous mapping functions (say as might be found in a sawtooth) where y0 represents the value of y for values of x <= to that given, and y1 is the value to be used for x > than that given). The list must start with x=0, end with x=1, and all values of x must be in increasing order. Values between the given mapping points are determined by simple linear interpolation. The function returns an array "result" where result[x*(N-1)] gives the closest value for values of x between 0 and 1. """ try: adata = array(data) except: raise TypeError("data must be convertable to an array") shape = adata.shape if len(shape) != 2 and shape[1] != 3: raise ValueError("data must be nx3 format") x = adata[:,0] y0 = adata[:,1] y1 = adata[:,2] if x[0] != 0. or x[-1] != 1.0: raise ValueError( "data mapping points must start with x=0. and end with x=1") if sometrue(sort(x)-x): raise ValueError( "data mapping points must have x in increasing order") # begin generation of lookup table x = x * (N-1) lut = zeros((N,), Float) xind = arange(float(N)) ind = searchsorted(x, xind)[1:-1] lut[1:-1] = ( divide(xind[1:-1] - take(x,ind-1), take(x,ind)-take(x,ind-1) ) *(take(y0,ind)-take(y1,ind-1)) + take(y1,ind-1)) lut[0] = y1[0] lut[-1] = y0[-1] # ensure that the lut is confined to values between 0 and 1 by clipping it lut = where(lut > 1., 1., lut) lut = where(lut < 0., 0., lut) return lut
def __call__(self, X, alpha=1.0): """ X is either a scalar or an array (of any dimension). If scalar, a tuple of rgba values is returned, otherwise an array with the new shape = oldshape+(4,). If the X-values are integers, then they are used as indices into the array. If they are floating point, then they must be in the interval (0.0, 1.0). Alpha must be a scalar. """ if not self._isinit: self._init() alpha = min(alpha, 1.0) # alpha must be between 0 and 1 alpha = max(alpha, 0.0) self._lut[:-3, -1] = alpha mask_bad = None if isinstance(X, (int, float)): vtype = 'scalar' xa = array([X]) else: vtype = 'array' xma = ma.asarray(X) xa = xma.filled(0) mask_bad = ma.getmaskorNone(xma) if typecode(xa) in typecodes['Float']: xa = where(xa == 1.0, 0.9999999, xa) # Tweak so 1.0 is in range. xa = (xa * self.N).astype(Int) mask_under = xa < 0 mask_over = xa > self.N-1 xa = where(mask_under, self._i_under, xa) xa = where(mask_over, self._i_over, xa) if mask_bad is not None: # and sometrue(mask_bad): xa = where(mask_bad, self._i_bad, xa) #print 'types', typecode(self._lut), typecode(xa), xa.shape rgba = take(self._lut, xa) if vtype == 'scalar': rgba = tuple(rgba[0,:]) #print rgba[0,1:10,:] # Now the same for numpy, numeric... return rgba
def __call__(self, X, alpha=1.0): """ X is either a scalar or an array (of any dimension). If scalar, a tuple of rgba values is returned, otherwise an array with the new shape = oldshape+(4,). If the X-values are integers, then they are used as indices into the array. If they are floating point, then they must be in the interval (0.0, 1.0). Alpha must be a scalar. """ if not self._isinit: self._init() alpha = min(alpha, 1.0) # alpha must be between 0 and 1 alpha = max(alpha, 0.0) self._lut[:-3, -1] = alpha mask_bad = None if isinstance(X, (int, float)): vtype = 'scalar' xa = array([X]) else: vtype = 'array' xma = ma.asarray(X) xa = xma.filled(0) mask_bad = ma.getmaskorNone(xma) if typecode(xa) in typecodes['Float']: xa = where(xa == 1.0, 0.9999999, xa) # Tweak so 1.0 is in range. xa = (xa * self.N).astype(Int) mask_under = xa < 0 mask_over = xa > self.N - 1 xa = where(mask_under, self._i_under, xa) xa = where(mask_over, self._i_over, xa) if mask_bad is not None: # and sometrue(mask_bad): xa = where(mask_bad, self._i_bad, xa) #print 'types', typecode(self._lut), typecode(xa), xa.shape rgba = take(self._lut, xa) if vtype == 'scalar': rgba = tuple(rgba[0, :]) #print rgba[0,1:10,:] # Now the same for numpy, numeric... return rgba
def __call__(self, X, alpha=1.0): """ X is either a scalar or an array (of any dimension). If scalar, a tuple of rgba values is returned, otherwise an array with the new shape = oldshape+(4,). If the X-values are integers, then they are used as indices into the array. If they are floating point, then they must be in the interval (0.0, 1.0). Alpha must be a scalar. """ if not self._isinit: self._init() alpha = min(alpha, 1.0) # alpha must be between 0 and 1 alpha = max(alpha, 0.0) self._lut[:-3, -1] = alpha mask_bad = None if not iterable(X): vtype = 'scalar' xa = array([X]) else: vtype = 'array' xma = ma.asarray(X) xa = xma.filled(0) mask_bad = ma.getmask(xma) if typecode(xa) in typecodes['Float']: putmask(xa, xa==1.0, 0.9999999) #Treat 1.0 as slightly less than 1. xa = (xa * self.N).astype(Int) # Set the over-range indices before the under-range; # otherwise the under-range values get converted to over-range. putmask(xa, xa>self.N-1, self._i_over) putmask(xa, xa<0, self._i_under) if mask_bad is not None and mask_bad.shape == xa.shape: putmask(xa, mask_bad, self._i_bad) rgba = take(self._lut, xa) if vtype == 'scalar': rgba = tuple(rgba[0,:]) return rgba
def clabel(self, *args, **kwargs): """ clabel(CS, **kwargs) - add labels to line contours in CS, where CS is a ContourSet object returned by contour. clabel(CS, V, **kwargs) - only label contours listed in V keyword arguments: * fontsize = None: as described in http://matplotlib.sf.net/fonts.html * colors = None: - a tuple of matplotlib color args (string, float, rgb, etc), different labels will be plotted in different colors in the order specified - one string color, e.g. colors = 'r' or colors = 'red', all labels will be plotted in this color - if colors == None, the color of each label matches the color of the corresponding contour * inline = True: controls whether the underlying contour is removed (inline = True) or not (False) * fmt = '%1.3f': a format string for the label """ fontsize = kwargs.get('fontsize', None) inline = kwargs.get('inline', 1) self.fmt = kwargs.get('fmt', '%1.3f') colors = kwargs.get('colors', None) if len(args) == 0: levels = self.levels indices = range(len(self.levels)) elif len(args) == 1: levlabs = list(args[0]) indices, levels = [], [] for i, lev in enumerate(self.levels): if lev in levlabs: indices.append(i) levels.append(lev) if len(levels) < len(levlabs): msg = "Specified levels " + str(levlabs) msg += "\n don't match available levels " msg += str(self.levels) raise ValueError(msg) else: raise TypeError("Illegal arguments to clabel, see help(clabel)") self.label_levels = levels self.label_indices = indices self.fp = FontProperties() if fontsize == None: font_size = int(self.fp.get_size_in_points()) else: if type(fontsize) not in [int, float, str]: raise TypeError("Font size must be an integer number.") # Can't it be floating point, as indicated in line above? else: if type(fontsize) == str: font_size = int(self.fp.get_size_in_points()) else: self.fp.set_size(fontsize) font_size = fontsize self.fslist = [font_size] * len(levels) if colors == None: self.label_mappable = self self.label_cvalues = take(self.cvalues, self.label_indices) else: cmap = ListedColormap(colors, N=len(self.label_levels)) self.label_cvalues = range(len(self.label_levels)) self.label_mappable = ScalarMappable(cmap=cmap, norm=no_norm()) #self.cl = [] # Initialized in ContourSet.__init__ #self.cl_cvalues = [] # same self.cl_xy = [] self.labels(inline) for label in self.cl: self.ax.add_artist(label) self.label_list = silent_list('Text', self.cl) return self.label_list
def autoscale(self): self.verify_intervals() dmin, dmax = self.dataInterval.get_bounds() dmin, dmax = self.nonsingular(dmin, dmax, expander = 0.05) return take(self.bin_boundaries(dmin, dmax), [0,-1])
def clabel(self, *args, **kwargs): """ clabel(CS, **kwargs) - add labels to line contours in CS, where CS is a ContourSet object returned by contour. clabel(CS, V, **kwargs) - only label contours listed in V keyword arguments: * fontsize = None: as described in http://matplotlib.sf.net/fonts.html * colors = None: - a tuple of matplotlib color args (string, float, rgb, etc), different labels will be plotted in different colors in the order specified - one string color, e.g. colors = 'r' or colors = 'red', all labels will be plotted in this color - if colors == None, the color of each label matches the color of the corresponding contour * inline = True: controls whether the underlying contour is removed (inline = True) or not (False) * fmt = '%1.3f': a format string for the label """ fontsize = kwargs.get('fontsize', None) inline = kwargs.get('inline', 1) self.fmt = kwargs.get('fmt', '%1.3f') colors = kwargs.get('colors', None) if len(args) == 0: levels = self.levels indices = range(len(self.levels)) elif len(args) == 1: levlabs = list(args[0]) indices, levels = [], [] for i, lev in enumerate(self.levels): if lev in levlabs: indices.append(i) levels.append(lev) if len(levels) < len(levlabs): msg = "Specified levels " + str(levlabs) msg += "\n don't match available levels " msg += str(self.levels) raise ValueError(msg) else: raise TypeError("Illegal arguments to clabel, see help(clabel)") self.label_levels = levels self.label_indices = indices self.fp = FontProperties() if fontsize == None: font_size = int(self.fp.get_size_in_points()) else: if type(fontsize) not in [int, float, str]: raise TypeError("Font size must be an integer number.") # Can't it be floating point, as indicated in line above? else: if type(fontsize) == str: font_size = int(self.fp.get_size_in_points()) else: self.fp.set_size(fontsize) font_size = fontsize self.fslist = [font_size] * len(levels) if colors == None: self.label_mappable = self self.label_cvalues = take(self.cvalues, self.label_indices) else: cmap = ListedColormap(colors, N=len(self.label_levels)) self.label_cvalues = range(len(self.label_levels)) self.label_mappable = ScalarMappable(cmap = cmap, norm = no_norm()) #self.cl = [] # Initialized in ContourSet.__init__ #self.cl_cvalues = [] # same self.cl_xy = [] self.labels(inline) for label in self.cl: self.ax.add_artist(label) self.label_list = silent_list('Text', self.cl) return self.label_list