Skip to content

Instantly share code, notes, and snippets.

@akira093
Created October 3, 2012 04:07
Show Gist options
  • Save akira093/3824938 to your computer and use it in GitHub Desktop.
Save akira093/3824938 to your computer and use it in GitHub Desktop.
#encoding:utf-8
from __future__ import division
import pylab
l = pylab.loadtxt("data")
l = l.T
l_ = pylab.np.polyfit(l[1],l[0],1)
def p(x, l_):
sum = 0
for i in range(len(l_)):
sum += l_[i]*x**(len(l_)-i-1)
return sum
def p_name(l_):
l = []
for i in range(len(l_)):
l.append("{0:1.3e}x^{1}".format(l_[i],len(l_)-i-1))
return "+".join(l)
pylab.title("Angle dependence of lattice constant")
pylab.xlabel(u"cos^2/sin")
pylab.ylabel("a[nm]")
pylab.plot(l[1],l[0],"x",label="test results")
pylab.plot(l[1],p(l[1],l_),"-",label = p_name(l_))
pylab.legend()
pylab.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment