'How to save a simple animation created using pause() command in python?

I saw examples of saving animations as gifs and movies which were created using the animation module. However, the one I tried is simpler animation using plt.pause() command. Pasted below

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)
  
# Ploting graph
    plt.plot(x, y, color = 'green')
    plt.pause(0.01)
plt.show()

Can anyone help with saving this plot as a video or a gif?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source