How to update a plot in Matplotlib? Last Updated : 17 Mar, 2021 Comments Improve Suggest changes Like Article Like Report In this article, let's discuss how to update a plot in Matplotlib. Updating a plot simply means plotting the data, then clearing the existing plot, and then again plotting the updated data and all these steps are performed in a loop. Functions Used:canvas.draw(): It is used to update a figure that has been changed. It will redraw the current figure.canvas.flush_events(): It holds the GUI event till the UI events have been processed. This will run till the loop ends and values will be updated continuously. Below is the implementation. Creating the data to plot using: Python3 x = np.linspace(0, 10*np.pi, 100) y = np.sin(x) Turn on interactive mode using: Python3 plt.ion() Now we will configure the plot (the ‘b-‘ indicates a blue line): Python3 fig = plt.figure() ax = fig.add_subplot(111) line1, = ax.plot(x, y, 'b-') And finally, update in a loop: Python3 for phase in np.linspace(0, 10*np.pi, 100): line1.set_ydata(np.sin(0.5 * x + phase)) fig.canvas.draw() fig.canvas.flush_events() Complete code. Python3 import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 10*np.pi, 100) y = np.sin(x) plt.ion() fig = plt.figure() ax = fig.add_subplot(111) line1, = ax.plot(x, y, 'b-') for phase in np.linspace(0, 10*np.pi, 100): line1.set_ydata(np.sin(0.5 * x + phase)) fig.canvas.draw() fig.canvas.flush_events() Output: Comment More infoAdvertise with us Next Article How to update a plot in Matplotlib? A aankit71 Follow Improve Article Tags : Technical Scripter Python Technical Scripter 2020 Python-matplotlib Practice Tags : python Similar Reads Matplotlib.axes.Axes.update() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 2 min read How to Add Title to Subplots in Matplotlib? In this article, we will see how to add a title to subplots in Matplotlib? Let's discuss some concepts : Matplotlib : 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 3 min read Matplotlib.axes.Axes.update_from() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 2 min read Matplotlib.pyplot.draw() in Python 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 2 min read How to add text to Matplotlib? Matplotlib is a plotting library in Python to visualize data, inspired by MATLAB, meaning that the terms used (Axis, Figure, Plots) will be similar to those used in MATLAB. Pyplot is a module within the Matplotlib library which is a shell-like interface to Matplotlib module. Â It provides almost any 5 min read Like