Hi,
I'm following the example in the gallery to do a barchart plot (see
http://matplotlib.sourceforge.net/examples/api/barchart_demo.html ).
In contrast to the example I would like to see the error bars only above
the bars, so I tried
rects2 = ax.bar(ind+width, womenMeans, width, color='y',
yerr=stds, error_kw = {'barsabove': True,
'ecolor' : 'k'}
While the 'ecolor' argument gets accepted, 'barsabove' apparently has no
effect (error bars still point up and downwards) - yet, no warning /
error is triggered. Where is my mistake? Or is this a bug (still using
version 1.0.1) with a known work-around?
TIA
Chris
Chris,
I don’t think “barsabove” does what you want. By “above”, it means that the errorbar is plotted in a layer on top of the plotting symbol rather than in the layer under it. Both ends will be plotted.
To get what you want, you might want to try (Note: untested):
rects2 = ax.bar(ind+width, womenMeans, width, color=‘y’,
yerr=np.vstack([[0]*len(stds), stds]), error_kw = {'ecolor' : 'k'})
When yerr is a 2xN numpy array, errorbars are plotted at y-yerr[0, :] and y+yerr[1,:]. So, np.vstack creates a 2xN array where the first row is all zeros and the second row is the stds values.
I hope that works for you!
Ben Root
···
On Wed, May 23, 2012 at 4:03 AM, Meesters, Aesku.Kipp Institute <meesters@…4092…> wrote:
Hi,
I’m following the example in the gallery to do a barchart plot (see
http://matplotlib.sourceforge.net/examples/api/barchart_demo.html ).
In contrast to the example I would like to see the error bars only above
the bars, so I tried
rects2 = ax.bar(ind+width, womenMeans, width, color=‘y’,
yerr=stds, error_kw = {'barsabove': True,
'ecolor' : 'k'}
While the ‘ecolor’ argument gets accepted, ‘barsabove’ apparently has no
effect (error bars still point up and downwards) - yet, no warning /
error is triggered. Where is my mistake? Or is this a bug (still using
version 1.0.1) with a known work-around?
TIA
Chris
Thanks, Ben. This is indeed what I was looking for and gives the desired
behavior.
Thanks a lot!
Chris
···
On Wed, 2012-05-23 at 08:55 -0400, Benjamin Root wrote:
On Wed, May 23, 2012 at 4:03 AM, Meesters, Aesku.Kipp Institute > <meesters@...4092...> wrote:
Hi,
I'm following the example in the gallery to do a barchart plot
(see
http://matplotlib.sourceforge.net/examples/api/barchart_demo.html ).
In contrast to the example I would like to see the error bars
only above
the bars, so I tried
rects2 = ax.bar(ind+width, womenMeans, width, color='y',
yerr=stds, error_kw = {'barsabove': True,
'ecolor' : 'k'}
While the 'ecolor' argument gets accepted, 'barsabove'
apparently has no
effect (error bars still point up and downwards) - yet, no
warning /
error is triggered. Where is my mistake? Or is this a bug
(still using
version 1.0.1) with a known work-around?
TIA
Chris
Chris,
I don't think "barsabove" does what you want. By "above", it means
that the errorbar is plotted in a layer on top of the plotting symbol
rather than in the layer under it. Both ends will be plotted.
To get what you want, you might want to try (Note: untested):
rects2 = ax.bar(ind+width, womenMeans, width, color='y',
yerr=np.vstack([[0]*len(stds), stds]), error_kw =
{'ecolor' : 'k'})
When yerr is a 2xN numpy array, errorbars are plotted at y-yerr[0, :]
and y+yerr[1,:]. So, np.vstack creates a 2xN array where the first row
is all zeros and the second row is the stds values.
I hope that works for you!
Ben Root