In R I can create the desired output by doing:
data = c(rep(1.5, 7), rep(2.5, 2), rep(3.5, 8),
rep(4.5, 3), rep(5.5, 1), rep(6.5, 8))
plot(density(data, bw=0.5))

In python (with matplotlib) the closest I got was with a simple histogram:
import matplotlib.pyplot as plt
data = [1.5]*7 + [2.5]*2 + [3.5]*8 + [4.5]*3 + [5.5]*1 + [6.5]*8
plt.hist(data, bins=6)
plt.show()

I also tried the normed=True parameter but couldn’t get anything other than trying to fit a gaussian to the histogram.
My latest attempts were around scipy.stats and gaussian_kde, following examples on the web, but I’ve been unsuccessful so far.
Sven has shown how to use the class
gaussian_kdefrom Scipy, but you will notice that it doesn’t look quite like what you generated with R. This is becausegaussian_kdetries to infer the bandwidth automatically. You can play with the bandwidth in a way by changing the functioncovariance_factorof thegaussian_kdeclass. First, here is what you get without changing that function:However, if I use the following code:
I get
which is pretty close to what you are getting from R. What have I done?
gaussian_kdeuses a changable function,covariance_factorto calculate its bandwidth. Before changing the function, the value returned by covariance_factor for this data was about .5. Lowering this lowered the bandwidth. I had to call_compute_covarianceafter changing that function so that all of the factors would be calculated correctly. It isn’t an exact correspondence with the bw parameter from R, but hopefully it helps you get in the right direction.