How to use pause() Function In Python

The pause() function in the pyplot module of the Matplotlib library is used to pause for interval seconds mentioned in the argument. Consider the below example in which we will create a simple linear graph using matplotlib and show Animation in it:

Example 1: Animated Plotting with Matplotlib in Python

In this example , below Python code uses Matplotlib to create an animated graph. Basically its generates points in a loop, updating the plot in real-time with a brief pause after each iteration then xlim and ylim functions set the graph’s axis limits, and plt.show() displays the final animated plot.

from matplotlib import pyplot as plt

x = []
y = []

for i in range(100):
    x.append(i)
    y.append(i)

    # Mention x and y limits to define their range
    plt.xlim(0, 100)
    plt.ylim(0, 100)
    
    # Plotting graph
    plt.plot(x, y, color = 'green')
    plt.pause(0.01)

plt.show()

Output : 

Similarly, you can use the pause() function to create Animation in various plots.

How to Create Animations in Python?

Animations are a great way to make Visualizations more attractive and user-appealing. It helps us to demonstrate Data Visualization in a Meaningful Way. Python helps us to create Animation Visualization using existing powerful Python libraries. Matplotlib is a very popular Data Visualisation Library and is the commonly used for the graphical representation of data and also for animations using inbuilt functions we will see in this article how to animating graphs using Pandas in Python and creating animated graphs with Pandas in Python.

Similar Reads

Create Animations in Python

There are two ways of Creating Animation using Matplotlib in Python :...

Using pause() Function

The pause() function in the pyplot module of the Matplotlib library is used to pause for interval seconds mentioned in the argument. Consider the below example in which we will create a simple linear graph using matplotlib and show Animation in it:...

Using FuncAnimation() Function

This FuncAnimation() Function does not create the Animation on its own, but it creates Animation from series of Graphics that we pass. Now there are Multiple types of Animation you can make using the FuncAnimation function:...