Skip to content

Commit

Permalink
Merge pull request #13 from ryanmartinneutrino/master
Browse files Browse the repository at this point in the history
Small fixes to plotting, added example notebooks
  • Loading branch information
Ryan Martin committed Sep 4, 2016
2 parents e4d932d + de405c4 commit 0cecb73
Show file tree
Hide file tree
Showing 7 changed files with 3,685 additions and 1,860 deletions.
File renamed without changes.
File renamed without changes.
1,856 changes: 1,856 additions & 0 deletions examples/jupyter/3_Load_data_into_plot.ipynb

Large diffs are not rendered by default.

406 changes: 406 additions & 0 deletions examples/jupyter/4_Interactive_Linear_Fit.ipynb

Large diffs are not rendered by default.

1,400 changes: 1,400 additions & 0 deletions examples/jupyter/5_Fitting_Data.ipynb

Large diffs are not rendered by default.

1,855 changes: 0 additions & 1,855 deletions examples/jupyter/Load_data_into_plot.ipynb

This file was deleted.

28 changes: 23 additions & 5 deletions qexpy/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,10 @@ def get_dataset(self, index=-1):
def add_residuals(self):
'''Add a subfigure with residuals to the main figure when plotting'''
self.set_yres_range_from_fits()
if self.datasets[-1].nfits>0:
self.show_residuals = True
for ds in self.datasets:
if ds.nfits > 0:
self.show_residuals = True
return


def add_function(self, function, pars = None, name=None, color=None):
Expand Down Expand Up @@ -683,9 +685,24 @@ def update(offset=pars[0].mean, offset_err=pars[0].std, slope=pars[1].mean,
interpolate=True)


start_x = self.dimensions_px[0] - 100 + self.fit_results_x_offset
start_x = self.dimensions_px[0] - 150 + self.fit_results_x_offset
start_y = self.dimensions_px[1] - 100 + self.fit_results_y_offset
textfit=str(omes)+"\n"+str(smes)

#calculate chi2
xdata = dataset.xdata
ydata = dataset.ydata
yerr = dataset.yerr
ymodel = offset+slope*xdata
yres = ydata-ymodel
chi2 = 0
ndof = 0
for i in range(xdata.size):
if yerr[i] != 0:
chi2 += (yres[i]/yerr[i])**2
ndof += 1
ndof -= 3 #2 parameters, -1

textfit=str(omes)+"\n"+str(smes)+"\n chi2/ndof: {:.3f}/{}".format(chi2, ndof)


plt.annotate(textfit,xy=(start_x, start_y), fontsize=11, horizontalalignment='right',
Expand All @@ -701,6 +718,7 @@ def update(offset=pars[0].mean, offset_err=pars[0].std, slope=pars[1].mean,
plt.legend(loc=self.mpl_legend_location)
plt.grid()
plt.show()


###Some wrapped matplotlib functions
def mpl_plot(self, *args, **kwargs):
Expand Down Expand Up @@ -888,7 +906,7 @@ def bk_plot_dataset(self, dataset, residual=False, color='black', show_fit_funct
if dataset.nfits > 0 and show_fit_function:
self.bk_plot_function(function=dataset.fit_function[-1], xdata=dataset.xdata,
pars=dataset.fit_pars[-1], n=50,
legend_name=dataset.fit_function_name[-1],
legend_name=dataset.name+"_"+dataset.fit_function_name[-1],
color=color, errorbandfactor=self.errorband_sigma)

def bk_add_points_with_error_bars(self, xdata, ydata, xerr=None, yerr=None,
Expand Down

0 comments on commit 0cecb73

Please sign in to comment.