Fitting a histogram with python

Here you have an example working on py2.6 and py3.2: from scipy.stats import norm import matplotlib.mlab as mlab import matplotlib.pyplot as plt # read data from a text file. One number per line arch = “test/Log(2)_ACRatio.txt” datos = [] for item in open(arch,’r’): item = item.strip() if item != ”: try: datos.append(float(item)) except ValueError: pass … Read more

Fitting a closed curve to a set of points

Actually, you were not far from the solution in your question. Using scipy.interpolate.splprep for parametric B-spline interpolation would be the simplest approach. It also natively supports closed curves, if you provide the per=1 parameter, import numpy as np from scipy.interpolate import splprep, splev import matplotlib.pyplot as plt # define pts from the question tck, u … Read more

fitting data with numpy

Unfortunately, np.polynomial.polynomial.polyfit returns the coefficients in the opposite order of that for np.polyfit and np.polyval (or, as you used np.poly1d). To illustrate: In [40]: np.polynomial.polynomial.polyfit(x, y, 4) Out[40]: array([ 84.29340848, -100.53595376, 44.83281408, -8.85931101, 0.65459882]) In [41]: np.polyfit(x, y, 4) Out[41]: array([ 0.65459882, -8.859311 , 44.83281407, -100.53595375, 84.29340846]) In general: np.polynomial.polynomial.polyfit returns coefficients [A, B, C] … Read more