How to create frequency scatter plot(like histogram but with dots instead of bars) and with optional error bars?

1.6k Views Asked by At

Does someone knows how in python(matplotlib, pandas_bokeh,...) plot frequency scatter plot with error bars, if it is called like that?
What I want is on y axis to have number of events(counts, instead of value) with the corresponding value in x axes, practically like histogram, but instead of bars, I would like to use dots. And possibly add error bars to mentioned dots.
It would look something like this:enter image description here

1

There are 1 best solutions below

2
On BEST ANSWER

Use a combination of numpy.hist and plt.errorbars:

import numpy as np
import matplotlib.pyplot as plt

x = np.random.normal(size=(20000, ))

hist, bin_edges = np.histogram(x, bins=50, density=False)
bin_center = (bin_edges[:-1] + bin_edges[1:])/2

plt.figure()
plt.hist(x, bins=50, density=False)
plt.errorbar(bin_center, hist, yerr=50, fmt='.')
plt.show()

enter image description here