Solved – Histogram for a sample in Python easily

histogrampython

Instead of this simplified-version of this file:

#!/usr/bin/env python
import numpy as np
import pylab as P


data = [x.rstrip().split("\t") for x in file(".data", "r").readlines()]
sdData = [float(x[1]) for x in data]
retData =[float(x[0]) for x in data]

# Calculating medians for estimating mean and sd
sdMed = sorted(sdData)[len(sdData)/2]
retMed= sorted(retData)[len(sdData)/2]


mu, sigma = retMed, sdMed
x = mu + sigma*P.randn(10000)

# the histogram of the data with histtype='step'
n, bins, patches = P.hist(x, 20, normed=1, histtype='stepfilled')
P.setp(patches, 'facecolor', 'g', 'alpha', 0.75)

# add a line showing the expected distribution
y = P.normpdf( bins, mu, sigma)
l = P.plot(bins, y, 'k--', linewidth=1.5)


#
# create a histogram by providing the bin edges (unequally spaced)
#
P.figure()
P.show()

is there something like this hist(SampleDataPoints)?

Best Answer

These demos look simpler.

Related Question