Updating the straight line in a loop in matplotlib

Here is the simple technique to update the straight line equation in a loop, this is very helpful to show the training process of parameters in case of a linear regression model or classification model.

# Use plt ion 
fig = plt.figure()
ax1 = fig.add_subplot(211)
for i in range(10):
    # Plot.
    ax1.scatter(xs, ys) 
    # update the figure.
    plt.plot(xs, i * xs, color='red')
    # Draw the line.
    # Clear the current plot.