Matplotlib.pyplot.draw() in Python
Last Updated :
19 Jun, 2025
matplotlib.pyplot.draw() function redraw the current figure in Matplotlib. Unlike plt.show(), it does not block the execution of code, making it especially useful in interactive sessions, real-time visualizations where the plot needs to update dynamically without pausing the program. Example:
Python
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.draw()
plt.pause(2)
Output
LineplotExplanation: A simple line plot is created with plt.plot([1, 2, 3], [4, 5, 6]), connecting points (1,4), (2,5) and (3,6). plt.draw() renders the plot without blocking execution and plt.pause(2) keeps it visible for 2 seconds.
Syntax
matplotlib.pyplot.draw()
Parameter: This function does not take any arguments.
Returns: This function does not return anything. It updates/redraws the current figure in-place.
Examples
Example 1: In this example, we create a simple plot, display it with an initial title and then update the title after a pause to reflect changes without blocking execution.
Python
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [3, 2, 5])
plt.title("Initial Title")
plt.draw()
plt.pause(1)
ax.set_title("Updated Title")
plt.draw()
plt.pause(2)
Output
Simple plotExplanation: The plot is first drawn with a title using plt.draw(). The title is then updated and plt.draw() is called again to reflect the change immediately.
Example 2: This example demonstrates how plt.draw() can be used in interactive mode to update the plot in each iteration of a loop with real-time data changes.
Python
import matplotlib.pyplot as plt
import numpy as np
plt.ion() # Turn on interactive mode
fig, ax = plt.subplots()
for i in range(5):
ax.clear()
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x + i)
ax.plot(x, y)
ax.set_title(f"Frame {i}")
plt.draw()
plt.pause(0.5)
Output
Real-time PlotExplanation: In interactive mode, the plot is cleared and redrawn with updated data in each iteration. plt.draw() reflects the updates in real-time without blocking code execution.
Example 3: Here, we rotate a 3D wireframe plot by updating the view angle in a loop using plt.draw() and plt.pause() to show animation-like behavior.
Python
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.draw()\
function Example', fontweight ="bold")
Output

Explanation: A 3D wireframe plot is created and rotated using ax.view_init(30, angle). plt.draw() updates the view each frame and plt.pause(0.001) enables smooth animation with dynamic title updates.
Similar Reads
Matplotlib.pyplot.gray() 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.gray() Function The gray() function in pyplot module of matplotlib library is used to s
2 min read
Matplotlib.pyplot.gca() in Python Matplotlib is a library in Python and it is a numerical - mathematical extension for the NumPy library. Pyplot is a state-based interface to a Matplotlib module that provides a MATLAB-like interface.  matplotlib.pyplot.gca() Function The gca() function in pyplot module of matplotlib library is used
2 min read
Matplotlib.pyplot.cla() 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. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot,
1 min read
Matplotlib.pyplot.axes() in Python axes() method in Matplotlib is used to create a new Axes instance (i.e., a plot area) within a figure. This allows you to specify the location and size of the plot within the figure, providing more control over subplot layout compared to plt.subplot(). It's key features include:Creates a new Axes at
3 min read
Matplotlib.pyplot.axis() in Python axis() function in Matplotlib is used to get or set properties of the x- and y-axis in a plot. It provides control over axis limits, aspect ratio and visibility, allowing customization of the plotâs coordinate system and view. It's key feature includes:Gets or sets the axis limits [xmin, xmax, ymin,
3 min read
Matplotlib.pyplot.ion() in Python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. The matplotlib.pyplot.ion() is used to turn on interactive mode. To check the status of
4 min read