matplotlib.pyplot.pause() in Python

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface.

matplotlib.pyplot.pause() Function:

The pause() function in pyplot module of matplotlib library is used to pause for interval seconds.

Syntax:

matplotlib.pyplot.pause(interval)

Parameters: This method does not accepts any parameters.

Return value: This method does not returns any value.



Below examples illustrate the matplotlib.pyplot.pause() function in matplotlib.pyplot:

Example #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
   
np.random.seed(19)
data = np.random.random((5, 10, 10))
  
   
for i in range(len(data)):
    plt.cla()
    plt.title('matplotlib.pyplot.pause() function Example\n\n Window {}'.format(i), fontweight ="bold")
    plt.imshow(data[i])
    plt.pause(0.1)

chevron_right


Output:

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Implementation of matplotlib function
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
   
fig = plt.figure()
ax = fig.add_subplot(111, projection ='3d')
   
X, Y, Z = axes3d.get_test_data(0.1)
ax.plot_wireframe(X, Y, Z, rstride = 5, cstride = 5)
   
for angle in range(0, 360):
    ax.view_init(30, angle)
    plt.draw()
    plt.pause(.001)
    ax.set_title('matplotlib.pyplot.pause() function Example', fontweight ="bold")

chevron_right


Output:

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Small things always make you to think big

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.