Exemple #1
0
def modelfit(data, uncert, indparams, model, nbins=75,
             fignum=-22, savefile=None, fmt="."):
  """
  Plot the binned dataset with given uncertainties and model curves
  as a function of indparams.
  In a lower panel, plot the residuals bewteen the data and model.

  Parameters
  ----------
  data:  1D float ndarray
    Input data set.
  uncert:  1D float ndarray
    One-sigma uncertainties of the data points.
  indparams:  1D float ndarray
    Independent variable (X axis) of the data points.
  model:  1D float ndarray
    Model of data.
  nbins:  Integer
    Number of bins in the output plot.
  fignum:  Integer
    The figure number.
  savefile:  Boolean
    If not None, name of file to save the plot.
  fmt:  String
    Format of the plotted markers.
  """

  # Bin down array:
  binsize = int((np.size(data)-1)/nbins + 1)
  bindata, binuncert, binindp = ba.binarray(data, uncert, indparams, binsize)
  binmodel = ba.weightedbin(model, binsize)
  fs = 14 # Font-size

  p = plt.figure(fignum, figsize=(8,6))
  p = plt.clf()

  # Residuals:
  a = plt.axes([0.15, 0.1, 0.8, 0.2])
  p = plt.errorbar(binindp, bindata-binmodel, binuncert, fmt='ko', ms=4)
  p = plt.plot([indparams[0], indparams[-1]], [0,0],'k:',lw=1.5)
  p = plt.xticks(size=fs)
  p = plt.yticks(size=fs)
  p = plt.xlabel("x", size=fs)
  p = plt.ylabel('Residuals', size=fs)

  # Data and Model:
  a = plt.axes([0.15, 0.35, 0.8, 0.55])
  p = plt.errorbar(binindp, bindata, binuncert, fmt='ko', ms=4,
                   label='Binned Data')
  p = plt.plot(indparams, model, "b", lw=2, label='Best Fit')
  p = plt.setp(a.get_xticklabels(), visible = False)
  p = plt.yticks(size=13)
  p = plt.ylabel('y', size=fs)
  p = plt.legend(loc='best')

  if savefile is not None:
      p = plt.savefig(savefile)
Exemple #2
0
def modelfit(data, uncert, indparams, model, nbins=75, title=None,
             fignum=-22, savefile=None):
  """
  Plot the model and (binned) data arrays, and their residuals.

  Parameters
  ----------
  data: 1D float ndarray
     The data array.
  uncert: 1D float ndarray
     Uncertainties of the data-array values.
  indparams: 1D float ndarray
     X-axis values of the data-array values.
  model: 1D ndarray
     The model of data (evaluated at indparams values).
  nbins: Integer
     Output number of data binned values.
  title: String
     Plot title.
  fignum: Integer
     The figure number.
  savefile: Boolean
     If not None, name of file to save the plot.
  """

  # Bin down array:
  binsize = (np.size(data)-1)/nbins + 1
  bindata, binuncert, binindp = ba.binarray(data, uncert, indparams, binsize)
  binmodel = ba.weightedbin(model, binsize)
  fs = 14 # Font-size

  p = plt.figure(fignum, figsize=(8,6))
  p = plt.clf()

  # Residuals:
  a = plt.axes([0.15, 0.1, 0.8, 0.2])
  p = plt.errorbar(binindp, bindata-binmodel, binuncert, fmt='ko', ms=4)
  p = plt.plot([indparams[0], indparams[-1]], [0,0],'k:',lw=1.5)
  p = plt.xticks(size=fs)
  p = plt.yticks(size=fs)
  p = plt.xlabel("x", size=fs)
  p = plt.ylabel('Residuals', size=fs)

  # Data and Model:
  a = plt.axes([0.15, 0.35, 0.8, 0.55])
  if title is not None:
    p = plt.title(title, size=fs)
  p = plt.errorbar(binindp, bindata, binuncert, fmt='ko', ms=4,
                   label='Binned Data')
  p = plt.plot(indparams, model, "b", lw=2, label='Best Fit')
  p = plt.setp(a.get_xticklabels(), visible = False)
  p = plt.yticks(size=13)
  p = plt.ylabel('y', size=fs)
  p = plt.legend(loc='best')

  if savefile is not None:
      p = plt.savefig(savefile)
Exemple #3
0
def modelfit(data,
             uncert,
             indparams,
             model,
             nbins=75,
             title=None,
             fignum=-22,
             savefile=None,
             fmt="."):
    """
  Doc me!
  """

    # Bin down array:
    binsize = (np.size(data) - 1) / nbins + 1
    bindata, binuncert, binindp = ba.binarray(data, uncert, indparams, binsize)
    binmodel = ba.weightedbin(model, binsize)
    fs = 14  # Font-size

    p = plt.figure(fignum, figsize=(8, 6))
    p = plt.clf()

    # Residuals:
    a = plt.axes([0.15, 0.1, 0.8, 0.2])
    p = plt.errorbar(binindp, bindata - binmodel, binuncert, fmt='ko', ms=4)
    p = plt.plot([indparams[0], indparams[-1]], [0, 0], 'k:', lw=1.5)
    p = plt.xticks(size=fs)
    p = plt.yticks(size=fs)
    p = plt.xlabel("x", size=fs)
    p = plt.ylabel('Residuals', size=fs)

    # Data and Model:
    a = plt.axes([0.15, 0.35, 0.8, 0.55])
    if title is not None:
        p = plt.title(title, size=fs)
    p = plt.errorbar(binindp,
                     bindata,
                     binuncert,
                     fmt='ko',
                     ms=4,
                     label='Binned Data')
    p = plt.plot(indparams, model, "b", lw=2, label='Best Fit')
    p = plt.setp(a.get_xticklabels(), visible=False)
    p = plt.yticks(size=13)
    p = plt.ylabel('y', size=fs)
    p = plt.legend(loc='best')

    if savefile is not None:
        p = plt.savefig(savefile)
Exemple #4
0
def modelfit(data,
             uncert,
             indparams,
             model,
             nbins=75,
             title=None,
             fignum=-22,
             savefile=None):
    """
  Plot the model and (binned) data arrays, and their residuals.

  Parameters
  ----------
  data: 1D float ndarray
     The data array.
  uncert: 1D float ndarray
     Uncertainties of the data-array values.
  indparams: 1D float ndarray
     X-axis values of the data-array values.
  model: 1D ndarray
     The model of data (evaluated at indparams values).
  nbins: Integer
     Output number of data binned values.
  title: String
     Plot title.
  fignum: Integer
     The figure number.
  savefile: Boolean
     If not None, name of file to save the plot.
  """

    # Bin down array:
    binsize = (np.size(data) - 1) / nbins + 1
    bindata, binuncert, binindp = ba.binarray(data, uncert, indparams, binsize)
    binmodel = ba.weightedbin(model, binsize)
    fs = 14  # Font-size

    p = plt.figure(fignum, figsize=(8, 6))
    p = plt.clf()

    # Residuals:
    a = plt.axes([0.15, 0.1, 0.8, 0.2])
    p = plt.errorbar(binindp, bindata - binmodel, binuncert, fmt='ko', ms=4)
    p = plt.plot([indparams[0], indparams[-1]], [0, 0], 'k:', lw=1.5)
    p = plt.xticks(size=fs)
    p = plt.yticks(size=fs)
    p = plt.xlabel("x", size=fs)
    p = plt.ylabel('Residuals', size=fs)

    # Data and Model:
    a = plt.axes([0.15, 0.35, 0.8, 0.55])
    if title is not None:
        p = plt.title(title, size=fs)
    p = plt.errorbar(binindp,
                     bindata,
                     binuncert,
                     fmt='ko',
                     ms=4,
                     label='Binned Data')
    p = plt.plot(indparams, model, "b", lw=2, label='Best Fit')
    p = plt.setp(a.get_xticklabels(), visible=False)
    p = plt.yticks(size=13)
    p = plt.ylabel('y', size=fs)
    p = plt.legend(loc='best')

    if savefile is not None:
        p = plt.savefig(savefile)