zn = polyfit(x, y, n)
pn = poly1d(zn)
q = 5
zq = polyfit(x, y, q)
pq = poly1d(zq)
xx = linspace(0, max(x), 500)
pylab.plot(xx, pn(xx), '-g', xx, pq(xx), '-b')
pylab.errorbar(x, y, xerr, yerr, fmt='r.')
pylab.legend(['degree ' + str(n), 'degree ' + str(q), 'data'])
pylab.axis([0, max(x), 0, max(y)])
pylab.xlabel('x label (unit)')
pylab.ylabel('y label (unit)')
pylab.show()
How to fit polynomial to data with error bars