def plotFitResult(fit, show_legend=True, show_plots=True, save_to_file=False,
foldername='', filename='', filetype='png'):
xvals = fit.xvals
yvals = fit.yvals
fit = fit.fitValues(xvals)
fig, ax = plt.subplots(1)
ax.plot(xvals, yvals, label='histogram', linewidth=3)
for n, f in enumerate(fit):
ax.plot(xvals, f, label='peak %i' % (n + 1), linewidth=6)
l2 = ax.legend(loc='upper center', bbox_to_anchor=(0.7, 1.05),
ncol=3, fancybox=True, shadow=True)
l2.set_visible(show_legend)
plt.xlabel('pixel value')
plt.ylabel('number of pixels')
if save_to_file:
p = PathStr(foldername).join(filename).setFiletype(filetype)
plt.savefig(p)
with open(PathStr(foldername).join('%s_params.csv' % filename), 'w') as f:
f.write('#x, #y, #fit\n')
for n, (x, y, ys) in enumerate(zip(xvals, yvals)):
fstr = ', '.join(str(f[n]) for f in fit)
f.write('%s, %s, %s\n' % (x, y, fstr))
if show_plots:
plt.show()
# REMOVE? or into scripts
评论列表
文章目录