Well, I seem to have really dove into this.
Here are 4 different patches against the latest svn of axes.py (rev
2495). Note that the rest of my install is the 0.87.3 release (I had to
copy over quiver.py to get the latest axes.py to work).
patch1 has the following changes to bar() and barh():
- fixed ignoring the rcParams['patch.facecolor'] for bar color: the
default value for the color arg is now None, and the Patch class is left
to handle fetching the rcparams['patch.facecolor']
- set default error bar color to None, so that errorbar() can handle
fetching the rcParams['lines.color']
- added an edgecolor keyword arg
- left and height can now both be scalars in bar(), same goes for x and
y in barh(). Previously, this raised a TypeError upon testing their
lengths. Code that preventively checked for this in barh() (but not in
bar()) has been removed.
- fixed a bug where patches would be cleared when error bars were
plotted if rcParams['axes.hold'] was False
- it looks like the code for barh() was copied from bar(), with some of
the args renamed. There was an error in the color checking code in
barh() where len(left) from bar() hadn't been properly renamed to len(x)
- found one or two changes that had been made to bar() that hadn't been
propagated to barh(), or vice versa
- rearranged the order of some code segments so that they follow the
order of the arguments
- updated the docstrings
Hopefully I haven't introduced any new bugs.
patch2 has everything in patch1, except it removes some code duplication
by calling bar() from within barh(). I thought this would be a good
idea, since it's easy to make a change in bar() and forget to do the
same in barh(). It turns out that this takes up almost as many lines of
code as having two independent functions, but this is only due to
inconsistent behaviour: barh() draws bars vertically centered on the y
values (ala matlab 6.0), while bar() draws bars aligned according to
their left edge (not ala matlab). I prefer the edge aligning behaviour.
It's easy to convert from one behaviour to the other, but I had to
duplicate all the error checking code before conversion, which bloated
it back up.
So... patch3 has everything in patch2, but renames the x and y args in
barh() to width and bottom respectively. This makes barh() draw bars
vertically aligned to their bottom edge, consistent with bar()'s
behaviour. Also, this makes hist(orientation='horizontal') do the same,
which makes it consistent with hist(orientation='vertical'). Finally, it
removes the code bloat mentioned above. However, it'll break any
existing code that relies on x or y as named args in barh(), or code
that expects barh() bars to be vertically centered on their y values.
And lastly... I find it odd that barh() has the width and bottom args
(formerly x and y) in that order: barh(width, bottom). The general
matlab convention is that the first argument is the positions, and the
second arg is the values. So it would make more sense to me to have
barh(bottom, width). That way, you could switch back and forth between
bar() and barh() and get the expected behaviour without having to switch
around the arguments. In fact, that's exactly how barh() in matlab 6
interprets the first two arguments: arg1 is the vertical positions, and
arg2 is the lengths of the bars at those positions. Same goes for
matlab's bar() function. As it is now in matplotlib, the first and
second arguments are interpreted differently for bar() and barh()
I don't know if anyone agrees with this change, but patch4 has all of
the changes in patch3, plus the order of the width and bottom args are
switched in barh(). This of course will break existing code that depends
on this order. I had to modify the barh() call in
hist(orientation='horizontal') to reflect this. I couldn't find any
other barh() call in matplotlib. For consistency, I also switched the
order of the yerr and xerr args, but these have default values and are
usually passed as keyword args, so this shouldn't break (much) code.
The patches are numbered in increasing order of preference. They look
rather big (and I'm not sure if my file compare util is bug-free). If
there seem to be problems with them, I can provide the full axes.py file
that corresponds to each patch.
Cheers,
Martin
--- C:\home\mspacek\Desktop\axes.svn2495.py 2006-06-20 16:56:06.000000000
-0700
+++ C:\home\mspacek\Desktop\axes.patch1.py 2006-06-22 03:31:27.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,183 +2361,265 @@
#### 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
):
"""
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)
- 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
-
- 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:
self.errorbar(
left+0.5*width, bottom+height,
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:
+ 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:
self.errorbar(
right, y,
yerr=yerr, xerr=xerr,
fmt=None, ecolor=ecolor, capsize=capsize)
+
+ self.hold(holdstate) # restore previous hold state
+
self.autoscale_view()
return patches
def stem(self, x, y, linefmt='b-', markerfmt='bo', basefmt='r-'):
"""
STEM(x, y, linefmt='b-', markerfmt='bo', basefmt='r-')
--- 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
--- C:\home\mspacek\Desktop\axes.svn2495.py 2006-06-20 16:56:06.000000000
-0700
+++ C:\home\mspacek\Desktop\axes.patch3.py 2006-06-22 03:40:35.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,219 @@
#### 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,
+ horizontal=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,
+ horizontal=False)
- Make a bar plot with rectangles at
+ Make a bar plot with rectangles bounded by
- left, left+width, 0, height
+ left, left+width, bottom, bottom+height (left, right, bottom and
top edges)
- left and height are Numeric arrays.
+ left, height, width, and bottom 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)
+ left - the x coordinates of the left sides of the bars
+
+ height - the heights of the bars
+
+ Optional arguments
+
+ width - the widths of the bars
+
+ bottom - the y coordinates of the bottom edges of the bars
+
+ color specifies the colors of the bars
+
+ edgecolor specifies the colors of the bar edges
+
xerr and yerr, if not None, will be used to generate errorbars
- on the bar chart
+ on the bar chart
- color specifies the color of the bar
-
ecolor specifies the color of any errorbar
capsize determines the length in points of the error bar caps
+ horizontal is a boolean that controls whether to interpret the
data for
+ plotting horizontal bars or vertical ones (the default)
- The optional arguments color, width and bottom can be either
- scalars or len(x) sequences
+ The optional arguments color, edgecolor, yerr, and xerr can be either
+ scalars or sequences of the appropriate length
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
+ def make_iterable(x):
+ if not iterable(x):
+ return [x]
+ else:
+ return x
+
+ # make them safe to take len() of
+ left = make_iterable(left)
+ height = make_iterable(height)
+ width = make_iterable(width)
+ bottom = make_iterable(bottom)
+
+ if not horizontal:
+ # resize width and bottom according to length of left
+ nbars = len(left)
+ if len(width) == 1:
+ width *= nbars
+ if len(bottom) == 1:
+ bottom *= nbars
+ else:
+ # resize left and height according to length of width
+ nbars = len(width)
+ if len(left) == 1:
+ left *= nbars
+ if len(height) == 1:
+ height *= nbars
+
left = asarray(left)
height = asarray(height)
-
- patches = []
-
+ width = asarray(width)
+ 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 nbars
if (is_string_like(color) or
- (iterable(color) and len(color)==3 and len(left)!=3) or
+ (iterable(color) and len(color)==3 and nbars!=3) or
not iterable(color)):
- color = [color]*len(left)
+ color = [color]*nbars
+ # if edgecolor looks like a color string, an RGB tuple or a
+ # scalar, then repeat it by nbars
+ if (is_string_like(edgecolor) or
+ (iterable(edgecolor) and len(edgecolor)==3 and nbars!=3) or
+ not iterable(edgecolor)):
+ edgecolor = [edgecolor]*nbars
- if not iterable(bottom):
- bottom = array([bottom]*len(left), Float)
+ if not iterable(yerr):
+ yerr = asarray([yerr]*nbars, Float) # Float converts Nones to NANs
else:
- bottom = asarray(bottom)
- if not iterable(width):
- width = array([width]*len(left), Float)
+ yerr = asarray(yerr)
+ if not iterable(xerr):
+ xerr = asarray([xerr]*nbars, Float)
else:
- width = asarray(width)
+ xerr = asarray(xerr)
- N = len(left)
- assert len(bottom)==N, 'bar arg bottom must be len(left)'
- 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(color)==N, 'bar arg color must be len(left) or scalar'
+ if not horizontal:
+ func = 'bar'
+ lenarg = 'left'
+ else:
+ func = 'barh'
+ lenarg = 'width'
+ assert len(left)==nbars, '%s argument \'left\' must be len(%s) or
scalar' % (func, lenarg)
+ assert len(height)==nbars, '%s argument \'height\' must be len(%s) or
scalar' % (func, lenarg)
+ assert len(width)==nbars, '%s argument \'width\' must be len(%s) or
scalar' % (func, lenarg)
+ assert len(bottom)==nbars, '%s argument \'bottom\' must be len(%s) or
scalar' % (func, lenarg)
+ assert len(color)==nbars, '%s argument \'color\' must be len(%s) or
scalar' % (func, lenarg)
+ assert len(edgecolor)==nbars, '%s argument \'edgecolor\' must be
len(%s) or scalar' % (func, lenarg)
+ assert len(yerr)==nbars, '%s argument \'yerr\' must be len(%s) or
scalar' % (func, lenarg)
+ assert len(xerr)==nbars, '%s argument \'xerr\' must be len(%s) or
scalar' % (func, lenarg)
- args = zip(left, bottom, width, height, color)
- for l, b, w, h, c in args:
+ patches = []
+
+ 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 horizontal:
+ 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
- ):
+
+ def barh(self, width, bottom, height=0.8, left=0,
+ 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)
+ BARH(width, bottom, height=0.8, left=0,
+ 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.
+ left, left+width, bottom, bottom+height (left, right, bottom and
top edges)
+
+ width, bottom, left, and height 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(width, bottom, height, left,
+ color, edgecolor, yerr, xerr, ecolor, capsize)
+
+ width - the lengths of the bars
+
+ bottom - the vertical positions of the bottom edges of the bars
+
Optional arguments
- height - the height (thickness) of the bar
+ height - the heights (thicknesses) of the bars
- left - the x coordinate of the left side of the bar
+ left - the x coordinates of the left edges of the bars
- color specifies the color of the bar
+ color specifies the colors of the bars
+ edgecolor specifies the colors of the bar edges
+
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
- scalars or len(x) sequences
+ The optional arguments color, edgecolor, yerr, and xerr can be either
+ scalars or sequences of the appropriate length
+
+ 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)
-
- patches = []
-
-
- # if color looks like a color string, and 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)):
- color = [color]*len(x)
-
-
- if not iterable(left):
- left = array([left]*len(x), Float)
- else:
- left = asarray(left)
- if not iterable(height):
- height = array([height]*len(x), Float)
- else:
- height = asarray(height)
-
- 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'
-
- 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,
+ horizontal=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
--- C:\home\mspacek\Desktop\axes.svn2495.py 2006-06-20 16:56:06.000000000
-0700
+++ C:\home\mspacek\Desktop\axes.patch4.py 2006-06-22 03:41:56.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,219 @@
#### 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,
+ horizontal=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,
+ horizontal=False)
- Make a bar plot with rectangles at
+ Make a bar plot with rectangles bounded by
- left, left+width, 0, height
+ left, left+width, bottom, bottom+height (left, right, bottom and
top edges)
- left and height are Numeric arrays.
+ left, height, width, and bottom 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)
+ left - the x coordinates of the left sides of the bars
+
+ height - the heights of the bars
+
+ Optional arguments
+
+ width - the widths of the bars
+
+ bottom - the y coordinates of the bottom edges of the bars
+
+ color specifies the colors of the bars
+
+ edgecolor specifies the colors of the bar edges
+
xerr and yerr, if not None, will be used to generate errorbars
- on the bar chart
+ on the bar chart
- color specifies the color of the bar
-
ecolor specifies the color of any errorbar
capsize determines the length in points of the error bar caps
+ horizontal is a boolean that controls whether to interpret the
data for
+ plotting horizontal bars or vertical ones (the default)
- The optional arguments color, width and bottom can be either
- scalars or len(x) sequences
+ The optional arguments color, edgecolor, yerr, and xerr can be either
+ scalars or sequences of the appropriate length
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
+ def make_iterable(x):
+ if not iterable(x):
+ return [x]
+ else:
+ return x
+
+ # make them safe to take len() of
+ left = make_iterable(left)
+ height = make_iterable(height)
+ width = make_iterable(width)
+ bottom = make_iterable(bottom)
+
+ if not horizontal:
+ # resize width and bottom according to length of left
+ nbars = len(left)
+ if len(width) == 1:
+ width *= nbars
+ if len(bottom) == 1:
+ bottom *= nbars
+ else:
+ # resize left and height according to length of bottom
+ nbars = len(bottom)
+ if len(left) == 1:
+ left *= nbars
+ if len(height) == 1:
+ height *= nbars
+
left = asarray(left)
height = asarray(height)
-
- patches = []
-
+ width = asarray(width)
+ 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 nbars
if (is_string_like(color) or
- (iterable(color) and len(color)==3 and len(left)!=3) or
+ (iterable(color) and len(color)==3 and nbars!=3) or
not iterable(color)):
- color = [color]*len(left)
+ color = [color]*nbars
+ # if edgecolor looks like a color string, an RGB tuple or a
+ # scalar, then repeat it by nbars
+ if (is_string_like(edgecolor) or
+ (iterable(edgecolor) and len(edgecolor)==3 and nbars!=3) or
+ not iterable(edgecolor)):
+ edgecolor = [edgecolor]*nbars
- if not iterable(bottom):
- bottom = array([bottom]*len(left), Float)
+ if not iterable(yerr):
+ yerr = asarray([yerr]*nbars, Float) # Float converts Nones to NANs
else:
- bottom = asarray(bottom)
- if not iterable(width):
- width = array([width]*len(left), Float)
+ yerr = asarray(yerr)
+ if not iterable(xerr):
+ xerr = asarray([xerr]*nbars, Float)
else:
- width = asarray(width)
+ xerr = asarray(xerr)
- N = len(left)
- assert len(bottom)==N, 'bar arg bottom must be len(left)'
- 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(color)==N, 'bar arg color must be len(left) or scalar'
+ if not horizontal:
+ func = 'bar'
+ lenarg = 'left'
+ else:
+ func = 'barh'
+ lenarg = 'bottom'
+ assert len(left)==nbars, '%s argument \'left\' must be len(%s) or
scalar' % (func, lenarg)
+ assert len(height)==nbars, '%s argument \'height\' must be len(%s) or
scalar' % (func, lenarg)
+ assert len(width)==nbars, '%s argument \'width\' must be len(%s) or
scalar' % (func, lenarg)
+ assert len(bottom)==nbars, '%s argument \'bottom\' must be len(%s) or
scalar' % (func, lenarg)
+ assert len(color)==nbars, '%s argument \'color\' must be len(%s) or
scalar' % (func, lenarg)
+ assert len(edgecolor)==nbars, '%s argument \'edgecolor\' must be
len(%s) or scalar' % (func, lenarg)
+ assert len(yerr)==nbars, '%s argument \'yerr\' must be len(%s) or
scalar' % (func, lenarg)
+ assert len(xerr)==nbars, '%s argument \'xerr\' must be len(%s) or
scalar' % (func, lenarg)
- args = zip(left, bottom, width, height, color)
- for l, b, w, h, c in args:
+ patches = []
+
+ 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 horizontal:
+ 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
- ):
+
+ def barh(self, bottom, width, height=0.8, left=0,
+ color=None, edgecolor=None, xerr=None, yerr=None, ecolor=None,
capsize=3
+ ):
"""
- BARH(x, y, height=0.8, left=0,
- color='b', yerr=None, xerr=None, ecolor='k', capsize=3)
+ BARH(bottom, width, height=0.8, left=0,
+ color=None, edgecolor=None, xerr=None, yerr=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.
+ left, left+width, bottom, bottom+height (left, right, bottom and
top edges)
+
+ bottom, width, height, and left 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(bottom, width, height, left,
+ color, edgecolor, xerr, yerr, ecolor, capsize)
+
+ bottom - the vertical positions of the bottom edges of the bars
+
+ width - the lengths of the bars
+
Optional arguments
- height - the height (thickness) of the bar
+ height - the heights (thicknesses) of the bars
- left - the x coordinate of the left side of the bar
+ left - the x coordinates of the left edges of the bars
- color specifies the color of the bar
+ color specifies the colors of the bars
+ edgecolor specifies the colors of the bar edges
+
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
- scalars or len(x) sequences
+ The optional arguments color, edgecolor, xerr, and yerr can be either
+ scalars or sequences of the appropriate length
+
+ 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)
-
- patches = []
-
-
- # if color looks like a color string, and 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)):
- color = [color]*len(x)
-
-
- if not iterable(left):
- left = array([left]*len(x), Float)
- else:
- left = asarray(left)
- if not iterable(height):
- height = array([height]*len(x), Float)
- else:
- height = asarray(height)
-
- 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'
-
- 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,
+ horizontal=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
@@ -3994,13 +4028,13 @@
hist bars
"""
if not self._hold: self.cla()
n,bins = matplotlib.mlab.hist(x, bins, normed)
if width is None: width = 0.9*(bins[1]-bins[0])
if orientation=='horizontal':
- patches = self.barh(n, bins, height=width, left=bottom)
+ patches = self.barh(bins, n, height=width, left=bottom)
else:
patches = self.bar(bins, n, width=width, bottom=bottom)
for p in patches:
p.update(kwargs)
return n, bins, silent_list('Patch', patches)
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel