def errorbar(x, y, e, u=None, fmt='b-'): """ Plot x versus y with error bars in e. if u is not None, then u gives the upper error bars and e gives the lower error bars. Otherwise e the error bars are symmetrix about y and given in the array e. fmt is the plot format symbol for y Return value is a length 2 tuple. The first element is a list of y symbol lines. The second element is a list of error bar lines. """ l0 = plot(x,y,fmt) e = to_arrays(Float, e) if u is None: u = e upper = y+u lower = y-e width = (max(x)-min(x))*0.005 a = gca() try: l1 = a.vlines(x, y, lower) l2 = a.vlines(x, y, upper) l3 = a.hlines(upper, x-width, x+width) l4 = a.hlines(lower, x-width, x+width) except ValueError, msg: msg = raise_msg_to_str(msg) error_msg(msg) raise RuntimeError, msg
def hist(x, bins=10, noplot=0, normed=0): """ Compute the histogram of x. bins is either an integer number of bins or a sequence giving the bins. x are the data to be binned. if noplot is True, just compute the histogram and return the number of observations and the bins as an (n, bins) tuple. If noplot is False, compute the histogram and plot it, returning n, bins, patches If normed is true, the first element of the return tuple will be the counts normalized to form a probability distribtion, ie, n/(len(x)*dbin) """ n, bins = mlab.hist(x, bins, normed) width = bins[1] - bins[0] if noplot: return n, bins else: try: patches = gca().bar(bins, n, width=width) except ValueError, msg: msg = raise_msg_to_str(msg) error_msg(msg) raise RuntimeError, msg
def errorbar(x, y, e, u=None, fmt='b-'): """ Plot x versus y with error bars in e. if u is not None, then u gives the upper error bars and e gives the lower error bars. Otherwise e the error bars are symmetrix about y and given in the array e. fmt is the plot format symbol for y Return value is a length 2 tuple. The first element is a list of y symbol lines. The second element is a list of error bar lines. """ l0 = plot(x, y, fmt) e = to_arrays(Float, e) if u is None: u = e upper = y + u lower = y - e width = (max(x) - min(x)) * 0.005 a = gca() try: l1 = a.vlines(x, y, lower) l2 = a.vlines(x, y, upper) l3 = a.hlines(upper, x - width, x + width) l4 = a.hlines(lower, x - width, x + width) except ValueError, msg: msg = raise_msg_to_str(msg) error_msg(msg) raise RuntimeError, msg
def hist(x, bins=10, noplot=0, normed=0): """ Compute the histogram of x. bins is either an integer number of bins or a sequence giving the bins. x are the data to be binned. if noplot is True, just compute the histogram and return the number of observations and the bins as an (n, bins) tuple. If noplot is False, compute the histogram and plot it, returning n, bins, patches If normed is true, the first element of the return tuple will be the counts normalized to form a probability distribtion, ie, n/(len(x)*dbin) """ n,bins = mlab.hist(x, bins, normed) width = bins[1]-bins[0] if noplot: return n, bins else: try: patches = gca().bar(bins, n, width=width) except ValueError, msg: msg = raise_msg_to_str(msg) error_msg(msg) raise RuntimeError, msg
def plot(*args, **kwargs): """ plot lines. *args is a variable length argument, allowing for multiple x, y pairs with an optional format string. For example, all of the following are legal plot(x,y) # plot Numeric arrays y vs x plot(x,y, 'bo') # plot Numeric arrays y vs x with blue circles plot(y) # plot y using x = arange(len(y)) plot(y, 'r+') # ditto with red plusses An arbitrary number of x, y, fmt groups can be specified, as in a.plot(x1, y1, 'g^', x2, y2, 'l-') Return value is a list of lines that were added The following line styles are supported: - : solid line -- : dashed line -. : dash-dot line : : dotted line | : verical lines . : points , : pixels o : circle symbols ^ : triangle up symbols v : triangle down symbols < : triangle left symbols > : triangle right symbols s : square symbols + : plus symbols The following color strings are supported b : blue g : green r : red c : cyan m : magenta y : yellow k : black w : white Line styles and colors are combined in a single format string """ try: lines = gca().plot(*args, **kwargs) except ValueError, msg: msg = raise_msg_to_str(msg) error_msg(msg)
def bar(*args, **kwargs): """ bar(self, x, y, width=0.8) Make a bar plot with rectangles at x, x+width, 0, y x and y are Numeric arrays Return value is a list of Rectangle patch instances """ try: patches = gca().bar(*args, **kwargs) except ValueError, msg: msg = raise_msg_to_str(msg) error_msg(msg) raise RuntimeError, msg
def vlines(*args, **kwargs): """ lines = vlines(x, ymin, ymax, color='k'): Plot vertical lines at each x from ymin to ymax. ymin or ymax can be scalars or len(x) numpy arrays. If they are scalars, then the respective values are constant, else the heights of the lines are determined by ymin and ymax Returns a list of lines that were added """ try: lines = gca().vlines(*args, **kwargs) except ValueError, msg: msg = raise_msg_to_str(msg) error_msg(msg) raise RuntimeError, msg
def hlines(*args, **kwargs): """ lines = hlines(self, y, xmin, xmax, fmt='k-') plot horizontal lines at each y from xmin to xmax. xmin or xmax can be scalars or len(x) numpy arrays. If they are scalars, then the respective values are constant, else the widths of the lines are determined by xmin and xmax Returns a list of line instances that were added """ try: lines = gca().hlines(*args, **kwargs) except ValueError, msg: msg = raise_msg_to_str(msg) error_msg(msg) raise RuntimeError, msg
def scatter(*args, **kwargs): """ scatter(self, x, y, s=None, c='b'): Make a scatter plot of x versus y. s is a size (in data coords) and can be either a scalar or an array of the same length as x or y. c is a color and can be a single color format string or an length(x) array of intensities which will be mapped by the colormap jet. If size is None a default size will be used """ try: patches = gca().scatter(*args, **kwargs) except ValueError, msg: msg = raise_msg_to_str(msg) error_msg(msg) raise RuntimeError, msg
def subplot(*args): """ Create a subplot command, creating axes with subplot(numRows, numCols, plotNum) where plotNum=1 is the first plot number and increasing plotNums fill rows first. max(plotNum)==numRows*numCols You can leave out the commas if numRows<=numCols<=plotNum<10, as in subplot(211) # 2 rows, 1 column, first (upper) plot subplot(111) is the default axis """ try: Gcf().get_current_figwin().add_subplot(*args) a = gca() except ValueError, msg: msg = raise_msg_to_str(msg) error_msg(msg) raise RuntimeError, msg
def set(h, s, val): """ Set handle h property in string s to value val h can be a handle or vector of handles. h is an instance (or vector of instances) of a class, eg a Line2D or an Axes or AxisText. if s is 'somename', this function calls o.set_somename(val) for every instance in o in h """ if not iterable(h): h = [h] else: h = flatten(h) for o in h: try: func = 'o.set_%s(val)' % s eval(func, {}, {'o': o, 'val': val}) except ValueError, msg: msg = raise_msg_to_str(msg) error_msg(msg) raise RuntimeError, msg
def set(h, s, val): """ Set handle h property in string s to value val h can be a handle or vector of handles. h is an instance (or vector of instances) of a class, eg a Line2D or an Axes or AxisText. if s is 'somename', this function calls o.set_somename(val) for every instance in o in h """ if not iterable(h): h = [h] else: h = flatten(h) for o in h: try: func = 'o.set_%s(val)' % s eval(func, {}, {'o': o, 'val' : val}) except ValueError, msg: msg = raise_msg_to_str(msg) error_msg(msg) raise RuntimeError, msg