- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Moving X-axis in Matplotlib during real-time plot
To move X-axis in Matplotlib during real-time plot, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create a figure and a set of subplots.
- Create x and y data points using numpy.
- Plot x and y data points using plot() method.
- Make an animation by repeatedly calling a function *animate* that moves the X-axis during real-time plot.
- To display the figure, use show() method.
Example
import matplotlib.pylab as plt import matplotlib.animation as animation import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() x = np.linspace(0, 15, 100) y = np.cos(x) ax.plot(x, y, lw=2, color='red') def animate(frame): ax.set_xlim(left=0, right=frame) ani = animation.FuncAnimation(fig, animate, frames=10) plt.show()
Output
- Related Articles
- Show the origin axis (x,y) in Matplotlib plot
- Adding caption below X-axis for a scatter plot using Matplotlib
- How to show date and time on the X-axis in Matplotlib?
- Annotate Time Series plot in Matplotlib
- How to plot two Pandas time series on the same plot with legends and secondary Y-axis in Matplotlib?
- How to remove or hide X-axis labels from a Seaborn / Matplotlib plot?
- How to plot data against specific dates on the X-axis using Matplotlib?
- Plot scatter points on polar axis in Matplotlib
- Adjusting the spacing between the edge of the plot and the X-axis in Matplotlib
- Matplotlib – How to plot the FFT of signal with correct frequencies on the X-axis?
- How to draw axis lines inside a plot in Matplotlib?
- Plot a histogram with Y-axis as percentage in Matplotlib
- How to customize the X-axis in Matplotlib?
- How to customize X-axis ticks in Matplotlib?
- Overlapping Y-axis tick label and X-axis tick label in Matplotlib

Advertisements