Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
feat: support smoother functions with nbins setting
Browse files Browse the repository at this point in the history
Co-authored-by: Chih-hsiang Cheng <ahsiang.c@gmail.com>
  • Loading branch information
henryiii and gitcheng committed Mar 2, 2021
1 parent 7c3f0ac commit 54769fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions probfit/costfunc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ cdef class Chi2Regression:
return 1.0

def draw(self, minuit=None, ax=None, parmloc=(0.05, 0.95), print_par=True,
args=None, errors=None, parts=False, no_plot=False):
args=None, errors=None, parts=False, nbins=None, no_plot=False):
"""
Draw comparison between points (**x**,**y**) and the function **f**.
Expand All @@ -666,13 +666,16 @@ cdef class Chi2Regression:
- **no_plot** Set this to true if you only want the return value
- **nbins** draw the PDF curve using this number of bins,
instead of (if None) using the data binning.
**Returns**
((data_x, data_y), (errorp,errorm), (total_pdf_x, total_pdf_y), parts)
"""
return plotting.draw_x2(self, minuit=minuit, ax=ax, parmloc=parmloc,
print_par=print_par, args=args, errors=errors, parts=parts,
no_plot=no_plot)
no_plot=no_plot, nbins=nbins)

def show(self, *arg, **kwd):
"""
Expand Down
8 changes: 6 additions & 2 deletions probfit/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def draw_residual_ulh(self, minuit=None, bins=100, ax=None, bound=None,


def draw_x2(self, minuit=None, ax=None, parmloc=(0.05, 0.95), print_par=True,
args=None, errors=None, grid=True, parts=False, no_plot=False):
args=None, errors=None, grid=True, parts=False, nbins=None, no_plot=False):
from matplotlib import pyplot as plt
error_ret = None
part_ret = []
Expand All @@ -262,7 +262,11 @@ def draw_x2(self, minuit=None, ax=None, parmloc=(0.05, 0.95), print_par=True,
draw_arg = [('lw', 2), ('zorder', 2)]
draw_arg.append(('color', 'r'))

total_ret = draw_pdf_with_midpoints(self.f, arg, x, ax=ax, no_plot=no_plot, **dict(draw_arg))
# Draw PDF curve(s)
if nbins is not None:
x = np.linspace(x[0],x[-1], nbins)

total_ret = draw_pdf_with_midpoints(self.f, arg, x, no_plot=no_plot, ax=ax, **dict(draw_arg))

if not no_plot:
ax.grid(grid)
Expand Down

0 comments on commit 54769fb

Please sign in to comment.