plot_fit

nbi_stat.plot_fit(x, y, delta, f, p, ep, xdelta=None, df=None, **kwargs)[source]

Plot data and a fitted funtion

Parameters:
  • x (array-like) – Independent variable of length N

  • y (array-like) – Dependent variable of length N

  • delta (array-like) – Uncertainty in y of length N

  • f (callable) – Fitted function with signature f(x,a,…)

  • p (array-like) – Best-fit parameter values of length Nf

  • ep (array-like) –

    Best-fit parameter uncertainties of length Nf, or the covariance of the fitted parameters of size (Nf,Nf).

    Note, if a vector (array of length Nf) is given, it must be the uncertainties (not the square uncertainties).

  • xdelta (array-like (optional)) – Uncertainty on x of length N. If specified, these uncertainties will be part of the chi^2 calculation and shown on the plot. If these uncertainties are not to be part of the chi^2 calculation, pass this array as the value of the keyword “xerr” in data_kw. Note, unless xeval is pass, this will change the range over which the function is evaluated to include the left and right most uncertainties of the data.

  • parameters (sequence (optional, default: None)) – List of names of parameters, or dictionary of options. If an entry is a dict, then it can have the keys - label: name of the parameter. If auto then a default name is chosen - scale: (default: None) Power of 10, or auto to scale by orders of magnitude - unit: (default: ‘’) Unit of the parameter. - nsig: (default: 1) Number of significant digits to round to Generic names are used if none is given. Note if scale or unit is set for a parameter, then the parameter value and uncertainty will be bracketed.

  • fit (bool or dict) – If false, do not plot fit. Otherwise if a dictionary pass these as keyword arguments to the fit plot call

  • band (bool or dict) –

    If false, do not plot uncertainty band. Otherwise pass value as keyword arguments to the drawing routine. - The keyword ‘factor’ applies a multiplicative factor

    to the uncertainty band (e.g., factor=2 will draw 2-sigma contour)

    • The keyword ‘step_factor’ value is applied for differentiation

  • data (bool or dict) –

    If false do not draw data. Otherwise, pass as keyword arguments to the drawing procedure. The keyword ‘plot’ can be set to a plotting function (e.g., matplotlib.pyplot.errorbar, which is also the default) with the signature

    plot(x,y,yerr,*args,**kwargs)

    The plotting function must draw in the current axes.

    If the keyword ‘xerr’ is present in this dictionary, then the function plot range is adjusted to encompass the end-points

  • legend (bool or dict) – If false, do not draw legend. Otherwise, pass as keyword arguments to the drawing procedure

  • table (bool or dict) – If false, do not draw parameter table. Otherwise, pass as keyword arguments to the drawing procedure

  • **kwargs (dict (optional)) –

    Other keyword arguments:

    xevalarray-like (optional)

    Specifies the independent variable (x) locations to evaluate the function at. If not specified the passed x locations are used. Here, one can pass for example the result of np.linspace(min,max,steps) to plot the function with better resolution than the passed x-coordinates would allow.

    nsigint (optional)

    Number of significant digits to show parameters with

    pvaluebool (optional, default=True)

    If true, show the chi^2 probability

    chi2bool or (float,int) (optional, default=True)

    If true, show chi^2. If pair of float and int, assume them to be the chi-sqaure and number of degrees of freedom, respectively.

    axesmatplotlib.pyplot.Axes (optional)

    Axes object to plot in. If none given, then in current axes

    dfcallable

    Derivative of f wrt. x. Only relevant if xdelta is given.

Returns:

  • dat (Artist) – Data artist

  • fit (Artist) – Fit artist

  • tab (Artist) – Table artist

  • leg (Artist) – Legend artist