Let $X_1, X_2, \dotsc, X_k$ be an i.i.d. sample of a random variable $X$. I plot these in a histogram and would like to include a confidence interval for the height of each histogram bar. Do you know how to go about doing it?
Let there be $i \in 1, \dots, I$ histogram bins. The probability of falling into a particular bin is $p_i$. This is just a binomial trial (i.e., you are either in the bin or not, each with a given probability).
If you are calculating the frequency of being in the bin (i.e., histograms with bars giving the set of $p_i$'s), then the variance should be $p_i(1-p_i)/k$.
If you are calculating total counts, then the variance is $p_i(1-p_i) \times k$.
The confidence interval can then be formed in the standard way.
Using the binomial variance $p (1-p) k$, as proposed in another answer, is only a good idea when the proportion is not near 0 or 1.
For better-behaved confidence intervals, there is extensive statistical literature e.g. Agresti & Coull (1998). Some of the proposed formulae are implemented in the R library
PropCIs. Here's an example creating a histogram with error bars using
PropCIs: Errorbars on histograms