How do I add error bars on a histogram?

I've created a histogram to see the number of similar values in a list.

data = np.genfromtxt("Pendel-Messung.dat")
stdm = (np.std(data))/((700)**(1/2))
breite = 700**(1/2)

fig2 = plt.figure()
ax1 = plt.subplot(111)
ax1.hist(data, bins=breite)
ax2 = ax1.twinx()

I want to create error bars (the error being stdm) in the middle of each bar of the histogram. I know I can create errorbars using

plt.errorbar("something", data, yerr = stdm) 

But how do I make them start in the middle of each bar? I thought of just adding breite/2, but that gives me an error.

Sorry, I'm a beginner! Thank you!


ax.hist returns the bin edges and the frequencies (n) so we can use those for x and y in the call to errorbar. Also, the bins input to hist takes either an integer for the number of bins, or a sequence of bin edges. I think you we trying to give a bin width of breite? If so, this should work (you just need to select an appropriate xmax):

n,bin_edges,patches = ax.hist(data,bins=np.arange(0,xmax,breite))

x = bin_edges[:-1]+breite/2.


Need Your Help

build html snippets with JSON data and inject the snippets into the DOM

javascript jquery single-page-application

I'm building a single page app similar to pininterest where I fetch JSON data in increments of 20. My project does not support Angularjs, backbone mustache or any such framework or libraries.