def hplot(name, h, err, xlab="", ylab="", hstr="h", rate=None, fit=True, fig=True):
from matplotlib.pyplot import figure, loglog, xlabel, ylabel, legend, show
if fig is True:
figure()
loglog(h, err, 's-', label=name)
if fit:
p = numpy.polyfit(numpy.log(h), numpy.log(err), 1)
C = numpy.exp(p[1])
alpha = p[0]
alg = [C*n**alpha for n in h]
loglog(h, alg, '--', label="%.3f*%s^(%.3f)" %(C, hstr, alpha))
if rate and h[0] != 0:
alg = [err[0]/(h[0]**rate)*n**rate for n in h]
loglog(h, alg, '--', label="%s^(%.3f)" %(hstr, rate))
xlabel(xlab)
ylabel(ylab)
legend(loc='best')
# --- create interpolation for different h and orders ---
评论列表
文章目录