Plot a 2-D linear regression (y = slope * x + offset) overlayed over the raw data samples

def regressionplot(x, y, poly=None):
    """
    Plot a 2-D linear regression (y = slope * x + offset) overlayed over the raw data samples
    """
    if not isinstance(x[0], (float, int, np.float64, np.float32)):
        x = [row[0] for row in x]
    y_regression = poly[0] * np.array(x) + poly[-1]
    try:
        plt.ion()
        fig = plt.figure()
        ax = fig.add_subplot(111)
        plt.plot(x, y_regression, 'r-', x, y, 'o', markersize=5)
        plt.legend(['%+.2g * x + %.2g' % poly, 'Samples'])
        ax.grid(True)
        plt.draw()
    except:
        logger.warn('No display available')
    return y_regression