--- C:\home\mspacek\Desktop\axes.svn2495.py 2006-06-20 16:56:06.000000000 -0700 +++ C:\home\mspacek\Desktop\axes.patch2.py 2006-06-22 03:31:16.000000000 -0700 @@ -2090,13 +2090,13 @@ autoscaled; default True. See Axes.autoscale_view for more information """ d = kwargs.copy() scalex = d.pop('scalex', True) - scaley = d.pop('scaley', True) + scaley = d.pop('scaley', True) if not self._hold: self.cla() lines = [] for line in self._get_lines(*args, **d): self.add_line(line) lines.append(line) lines = [line for line in lines] # consume the generator @@ -2361,185 +2361,252 @@ #### Specialized plotting def bar(self, left, height, width=0.8, bottom=0, - color='b', yerr=None, xerr=None, ecolor='k', capsize=3 + color=None, edgecolor=None, yerr=None, xerr=None, ecolor=None, capsize=3, + herr=False ): """ BAR(left, height, width=0.8, bottom=0, - color='b', yerr=None, xerr=None, ecolor='k', capsize=3) + color=None, edgecolor=None, yerr=None, xerr=None, ecolor=None, capsize=3, + herr=False) - Make a bar plot with rectangles at + Make a bar plot with rectangles bounded by - left, left+width, 0, height + left, left+width, 0, height (left, right, bottom and top edges) - left and height are Numeric arrays. + left and height can be either scalars or sequences Return value is a list of Rectangle patch instances BAR(left, height, width, bottom, - color, yerr, xerr, capsize, yoff) + color, edgecolor, yerr, xerr, ecolor, capsize) - xerr and yerr, if not None, will be used to generate errorbars - on the bar chart + left - the x coordinates of the left sides of the bars + + height - the heights of the bars + + Optional arguments + + width - the width of the bar + bottom - the y coordinate of the bottom edge of the bar + color specifies the color of the bar + edgecolor specifies the color of the bar edge + + xerr and yerr, if not None, will be used to generate errorbars + on the bar chart + ecolor specifies the color of any errorbar capsize determines the length in points of the error bar caps + herr is a boolean that controls whether to plot the error bars as if + this were a horizontal bar plot - The optional arguments color, width and bottom can be either - scalars or len(x) sequences + The optional arguments width, bottom, color, edgecolor, yerr, and xerr can be either + scalars or len(left) sequences This enables you to use bar as the basis for stacked bar charts, or candlestick plots """ if not self._hold: self.cla() - # left = asarray(left) - width/2 - left = asarray(left) - height = asarray(height) + if not iterable(left): + left = asarray([left]) + else: + left = asarray(left) + if not iterable(height): + height = asarray([height]) + else: + height = asarray(height) patches = [] + if not iterable(width): + width = array([width]*len(left), Float) + else: + width = asarray(width) + if not iterable(bottom): + bottom = array([bottom]*len(left), Float) + else: + bottom = asarray(bottom) # if color looks like a color string, an RGB tuple or a - # scalar, then repeat it by len(x) + # scalar, then repeat it by len(left) if (is_string_like(color) or (iterable(color) and len(color)==3 and len(left)!=3) or not iterable(color)): color = [color]*len(left) + # if edgecolor looks like a color string, an RGB tuple or a + # scalar, then repeat it by len(left) + if (is_string_like(edgecolor) or + (iterable(edgecolor) and len(edgecolor)==3 and len(left)!=3) or + not iterable(edgecolor)): + edgecolor = [edgecolor]*len(left) - if not iterable(bottom): - bottom = array([bottom]*len(left), Float) + if not iterable(yerr): + yerr = array([yerr]*len(left), Float) else: - bottom = asarray(bottom) - if not iterable(width): - width = array([width]*len(left), Float) + yerr = asarray(yerr) + if not iterable(xerr): + xerr = array([xerr]*len(left), Float) else: - width = asarray(width) + xerr = asarray(xerr) N = len(left) - assert len(bottom)==N, 'bar arg bottom must be len(left)' + assert len(height)==N, 'bar arg height must be len(left) or scalar' assert len(width)==N, 'bar arg width must be len(left) or scalar' - assert len(height)==N, 'bar arg height must be len(left) or scalar' + assert len(bottom)==N, 'bar arg bottom must be len(left) or scalar' assert len(color)==N, 'bar arg color must be len(left) or scalar' + assert len(edgecolor)==N, 'bar arg edgecolor must be len(left) or scalar' + assert len(yerr)==N, 'bar arg yerr must be len(left) or scalar' + assert len(xerr)==N, 'bar arg xerr must be len(left) or scalar' - args = zip(left, bottom, width, height, color) - for l, b, w, h, c in args: + args = zip(left, bottom, width, height, color, edgecolor) + for l, b, w, h, c, e in args: if h<0: b += h h = abs(h) r = Rectangle( xy=(l, b), width=w, height=h, facecolor=c, + edgecolor=e, ) self.add_patch(r) patches.append(r) + holdstate = self._hold + self.hold(True) # ensure hold is on before plotting errorbars if xerr is not None or yerr is not None: + if not herr: + x, y = left+0.5*width, bottom+height + else: + x, y = left+width, bottom+0.5*height self.errorbar( - left+0.5*width, bottom+height, + x, y, yerr=yerr, xerr=xerr, fmt=None, ecolor=ecolor, capsize=capsize) + + self.hold(holdstate) # restore previous hold state + self.autoscale_view() return patches + def barh(self, x, y, height=0.8, left=0, - color='b', yerr=None, xerr=None, ecolor='k', capsize=3 - ): + color=None, edgecolor=None, yerr=None, xerr=None, ecolor=None, capsize=3 + ): """ BARH(x, y, height=0.8, left=0, - color='b', yerr=None, xerr=None, ecolor='k', capsize=3) + color=None, edgecolor=None, yerr=None, xerr=None, ecolor=None, capsize=3) - BARH(x, y) + Make a horizontal bar plot with rectangles bounded by - The y values give the heights of the center of the bars. The - x values give the length of the bars. + 0, x, y-height/2, y+height/2 (left, right, bottom and top edges) + + x and y can be either scalars or sequences - Return value is a list of Rectangle patch instances + Return value is a list of Rectangle patch instances + BARH(x, y, height, left, + color, edgecolor, yerr, xerr, ecolor, capsize) + + x - lengths of the bars + + y - the vertical positions of the center of the bars + Optional arguments - height - the height (thickness) of the bar + height - the height (thickness) of the bar - left - the x coordinate of the left side of the bar + left - the x coordinate of the left side of the bar color specifies the color of the bar + edgecolor specifies the color of the bar edge + xerr and yerr, if not None, will be used to generate errorbars on the bar chart ecolor specifies the color of any errorbar capsize determines the length in points of the error bar caps - The optional arguments color, height and left can be either + The optional arguments height, left, color, edgecolor, yerr, and xerr can be either scalars or len(x) sequences + + This enables you to use barh as the basis for stacked bar + charts, or candlestick plots """ - if not self._hold: self.cla() - # left = asarray(left) - width/2 - x = asarray(x) - y = asarray(y) + if not iterable(x): + x = asarray([x]) + else: + x = asarray(x) + if not iterable(y): + y = asarray([y]) + else: + y = asarray(y) - patches = [] - + if not iterable(height): + height = array([height]*len(x), Float) + else: + height = asarray(height) + if not iterable(left): + left = array([left]*len(x), Float) + else: + left = asarray(left) - # if color looks like a color string, and RGB tuple or a + # if color looks like a color string, an RGB tuple or a # scalar, then repeat it by len(x) if (is_string_like(color) or - (iterable(color) and len(color)==3 and - iterable(left) and len(left)!=3) or not iterable(color)): + (iterable(color) and len(color)==3 and len(x)!=3) or + not iterable(color)): color = [color]*len(x) + # if edgecolor looks like a color string, an RGB tuple or a + # scalar, then repeat it by len(x) + if (is_string_like(edgecolor) or + (iterable(edgecolor) and len(edgecolor)==3 and len(x)!=3) or + not iterable(edgecolor)): + edgecolor = [edgecolor]*len(x) - if not iterable(left): - left = array([left]*len(x), Float) + if not iterable(yerr): + yerr = array([yerr]*len(left), Float) else: - left = asarray(left) - if not iterable(height): - height = array([height]*len(x), Float) + yerr = asarray(yerr) + if not iterable(xerr): + xerr = array([xerr]*len(left), Float) else: - height = asarray(height) + xerr = asarray(xerr) N = len(x) - assert len(left)==N, 'bar arg left must be len(x)' - assert len(height)==N, 'bar arg height must be len(x) or scalar' - assert len(y)==N, 'bar arg y must be len(x) or scalar' - assert len(color)==N, 'bar arg color must be len(x) or scalar' + assert len(y)==N, 'barh arg y must be len(x) or scalar' + assert len(height)==N, 'barh arg height must be len(x) or scalar' + assert len(left)==N, 'barh arg left must be len(x) or scalar' + assert len(color)==N, 'barh arg color must be len(x) or scalar' + assert len(edgecolor)==N, 'barh arg edgecolor must be len(x) or scalar' + assert len(yerr)==N, 'barh arg yerr must be len(x) or scalar' + assert len(xerr)==N, 'barh arg xerr must be len(x) or scalar' width = x - right = left+x bottom = y - height/2. - args = zip(left, bottom, width, height, color) - for l, b, w, h, c in args: - if h<0: - b += h - h = abs(h) - r = Rectangle( - xy=(l, b), width=w, height=h, - facecolor=c, - ) - self.add_patch(r) - patches.append(r) - - if xerr is not None or yerr is not None: - self.errorbar( - right, y, - yerr=yerr, xerr=xerr, - fmt=None, ecolor=ecolor, capsize=capsize) - self.autoscale_view() + patches = self.bar(left=left, height=height, width=width, bottom=bottom, + color=color, edgecolor=edgecolor, yerr=yerr, xerr=xerr, ecolor=ecolor, capsize=capsize, + herr=True + ) return patches + def stem(self, x, y, linefmt='b-', markerfmt='bo', basefmt='r-'): """ STEM(x, y, linefmt='b-', markerfmt='bo', basefmt='r-') A stem plot plots vertical lines (using linefmt) at each x location