code: def plot_reg(xvals, yvals, poly, x_label="x", y_label="y", data_label="data",
               reg_label="regression line", fname=None):
    
    # local import to avoid dependency for non-debug use
    import matplotlib.pyplot as plt
    plt.plot(xvals, yvals, "bo", label=data_label)
    if not (poly is None):
      plt.plot(xvals, np.polyval(poly, xvals), "r-", label=reg_label)
    plt.xlabel(x_label)
    plt.ylabel(y_label)
    plt.legend(loc="best")
    if fname is None:
      plt.show()
    else:
      plt.savefig(fname)
    plt.close()
docs: Helper function to plot trend lines for line-fitting approaches. This
    function will show a plot through ``plt.show()`` and close it after the window
    has been closed by the user.
  
    Args:
      xvals (list/array of float):
        list of x-values
      yvals (list/array of float):
        list of y-values
      poly (list/array of float):
        polynomial parameters as accepted by ``np.polyval``
    Kwargs:
      x_label (str):
        label of the x-axis
      y_label (str):
        label of the y-axis
      data_label (str):
        label of the data
      reg_label(str):
        label of the regression line
      fname (str):
        file name (if not None, the plot will be saved to disc instead of
        showing it though ``plt.show()``)