0

I'm a TOTAL beginner, so sorry if this is easily solved. I am trying to put error bars on this histogram; I already have the error I want to use. It seems like everything I try just causes some sort of error that I don't understand. How would you approach this? I know this question has been asked on stack overflow plenty of times before, but every time I try to use a solution from those questions, I just get endless errors. Is there something fundamentally wrong with what I'm doing?

plt.figure()
#plotting histogram of data
result = plt.hist(zvel, bins=20)

#Plotting gaussian distribution to fit over it
mean = np.mean(zvel)
variance = np.var(zvel)
sigma = np.sqrt(variance)
x = np.linspace(min(zvel), max(zvel), 100)
dx = result[1][1] - result[1][0]
scale = len(zvel)*dx
plt.plot(x, mlab.normpdf(x, mean, sigma)*scale)
Rachel
  • 1
  • 1
  • `plt.errorbar([0,1],[1,2], yerr=[2,3])`? – Quang Hoang Sep 23 '19 at 18:31
  • It would be helpful to see the values of the errors you have. Basically, since you are plotting an histogram with 20 bins, you should have 20 error values corresponding to each of the bins of the histogram. Is that the case? – Diziet Asahi Sep 23 '19 at 19:55

1 Answers1

0

You need to use a bar chart type, instead of histogram type to get error bars. Then you put the error bars on each bar.

See previous question, Matplotlib histogram with errorbars

However, I suggest to describe your errors in your question, i.e. What do the errors say? So you can get specific help.

Also, I agree with the comment, that it would be helpful to check the errors to make sure the errors array is correct.

Maria Stone
  • 21
  • 1
  • 5