Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dbf28b4

Browse files
committed
Axes.bar: added error_kw kwarg
svn path=/trunk/matplotlib/; revision=8369
1 parent 6ca4756 commit dbf28b4

4 files changed

Lines changed: 41 additions & 17 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2010-06-02 Add error_kw kwarg to Axes.bar(). - EF
2+
13
2010-06-01 Fix pcolormesh() and QuadMesh to pass on kwargs as
24
appropriate. - RM
35

doc/api/api_changes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ list may help describe what changes may be necessary in your code.
1010
Changes beyond 0.99.x
1111
=====================
1212

13+
* The :meth:`matplotlib.axes.Axes.bar` method accepts a *error_kw*
14+
kwarg; it is a dictionary of kwargs to be passed to the
15+
errorbar function.
16+
1317
* The :meth:`matplotlib.axes.Axes.hist` *color* kwarg now accepts
1418
a sequence of color specs to match a sequence of datasets.
1519

examples/pylab_examples/barchart_demo.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212

1313

1414
plt.subplot(111)
15-
rects1 = plt.bar(ind, menMeans, width, color='r', yerr=menStd)
15+
rects1 = plt.bar(ind, menMeans, width,
16+
color='r',
17+
yerr=menStd,
18+
error_kw=dict(elinewidth=6, ecolor='pink'))
1619

1720
womenMeans = (25, 32, 34, 20, 25)
1821
womenStd = (3, 5, 2, 3, 3)
19-
rects2 = plt.bar(ind+width, womenMeans, width, color='y', yerr=womenStd)
22+
rects2 = plt.bar(ind+width, womenMeans, width,
23+
color='y',
24+
yerr=womenStd,
25+
error_kw=dict(elinewidth=6, ecolor='yellow'))
2026

2127
# add some
2228
plt.ylabel('Scores')

lib/matplotlib/axes.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4288,6 +4288,10 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
42884288
*ecolor* specifies the color of any errorbar
42894289
*capsize* (default 3) determines the length in
42904290
points of the error bar caps
4291+
*error_kw* dictionary of kwargs to be passed to
4292+
errorbar method. *ecolor* and *capsize*
4293+
may be specified here rather than as
4294+
independent kwargs.
42914295
*align* 'edge' (default) | 'center'
42924296
*orientation* 'vertical' | 'horizontal'
42934297
*log* [False|True] False (default) leaves the
@@ -4322,13 +4326,18 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
43224326
color = kwargs.pop('color', None)
43234327
edgecolor = kwargs.pop('edgecolor', None)
43244328
linewidth = kwargs.pop('linewidth', None)
4329+
43254330
# Because xerr and yerr will be passed to errorbar,
43264331
# most dimension checking and processing will be left
43274332
# to the errorbar method.
43284333
xerr = kwargs.pop('xerr', None)
43294334
yerr = kwargs.pop('yerr', None)
4335+
error_kw = kwargs.pop('error_kw', dict())
43304336
ecolor = kwargs.pop('ecolor', None)
43314337
capsize = kwargs.pop('capsize', 3)
4338+
error_kw.setdefault('ecolor', ecolor)
4339+
error_kw.setdefault('capsize', capsize)
4340+
43324341
align = kwargs.pop('align', 'edge')
43334342
orientation = kwargs.pop('orientation', 'vertical')
43344343
log = kwargs.pop('log', False)
@@ -4478,7 +4487,7 @@ def make_iterable(x):
44784487
self.errorbar(
44794488
x, y,
44804489
yerr=yerr, xerr=xerr,
4481-
fmt=None, ecolor=ecolor, capsize=capsize)
4490+
fmt=None, **error_kw)
44824491

44834492
self.hold(holdstate) # restore previous hold state
44844493

@@ -4833,17 +4842,17 @@ def errorbar(self, x, y, yerr=None, xerr=None,
48334842
If a scalar number, len(N) array-like object, or an Nx1 array-like
48344843
object, errorbars are drawn +/- value.
48354844
4836-
If a rank-1, 2xN numpy array, errorbars are drawn at -row1 and
4845+
If a sequence of shape 2xN, errorbars are drawn at -row1 and
48374846
+row2
48384847
48394848
*fmt*: '-'
4840-
The plot format symbol for *y*. If *fmt* is *None*, just plot the
4841-
errorbars with no line symbols. This can be useful for creating a
4842-
bar plot with errorbars.
4849+
The plot format symbol. If *fmt* is *None*, only the
4850+
errorbars are plotted. This is used for adding
4851+
errorbars to a bar plot, for example.
48434852
48444853
*ecolor*: [ None | mpl color ]
4845-
a matplotlib color arg which gives the color the errorbar lines; if
4846-
*None*, use the marker color.
4854+
a matplotlib color arg which gives the color the errorbar lines;
4855+
if *None*, use the marker color.
48474856
48484857
*elinewidth*: scalar
48494858
the linewidth of the errorbar lines. If *None*, use the linewidth.
@@ -4862,8 +4871,7 @@ def errorbar(self, x, y, yerr=None, xerr=None,
48624871
type as *xerr* and *yerr*.
48634872
48644873
All other keyword arguments are passed on to the plot command for the
4865-
markers, so you can add additional key=value pairs to control the
4866-
errorbar markers. For example, this code makes big red squares with
4874+
markers, For example, this code makes big red squares with
48674875
thick green edges::
48684876
48694877
x,y,yerr = rand(3,10)
@@ -4878,12 +4886,16 @@ def errorbar(self, x, y, yerr=None, xerr=None,
48784886
48794887
%(Line2D)s
48804888
4881-
Return value is a length 3 tuple. The first element is the
4882-
:class:`~matplotlib.lines.Line2D` instance for the *y* symbol
4883-
lines. The second element is a list of error bar cap lines,
4884-
the third element is a list of
4885-
:class:`~matplotlib.collections.LineCollection` instances for
4886-
the horizontal and vertical error ranges.
4889+
Returns (*plotline*, *caplines*, *barlinecols*):
4890+
4891+
*plotline*: :class:`~matplotlib.lines.Line2D` instance
4892+
*x*, *y* plot markers and/or line
4893+
4894+
*caplines*: list of error bar cap
4895+
:class:`~matplotlib.lines.Line2D` instances
4896+
*barlinecols*: list of
4897+
:class:`~matplotlib.collections.LineCollection` instances for
4898+
the horizontal and vertical error ranges.
48874899
48884900
**Example:**
48894901

0 commit comments

Comments
 (0)