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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s