

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Updating the X-axis values using Matplotlib animation
To update the X-axis values using Matplotlib animation, 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 on axis (ax).
- Make an animation by repeatedly calling a function animate that sets the X-axis value as per the frame.
- 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.sin(x) ax.plot(x, y, lw=7) def animate(frame): ax.set_xlim(left=0, right=frame) ani = animation.FuncAnimation(fig, animate, frames=10) plt.show()
Output
- Related Questions & Answers
- How to set X-axis values in Matplotlib Python?
- Aligning table to X-axis using matplotlib Python
- How to add footnote under the X-axis using Matplotlib?
- How to customize the X-axis in Matplotlib?
- How to force Matplotlib to show the values on X-axis as integers?
- Show the origin axis (x,y) in Matplotlib plot
- Increasing the space for X-axis labels in Matplotlib
- Remove the X-axis ticks while keeping the grids (Matplotlib)
- How to plot data against specific dates on the X-axis using Matplotlib?
- Filling the region between a curve and X-axis in Python using Matplotlib
- Creating 3D animation using matplotlib
- How to change the range of the X-axis and Y-axis in Matplotlib?
- Adding caption below X-axis for a scatter plot using Matplotlib
- How to customize X-axis ticks in Matplotlib?
- How to append a single labeled tick to X-axis using matplotlib?
Advertisements