- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
How to update the plot title with Matplotlib using animation?
To update the plot title with Matplotlib using animation, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create a new figure or activate an existing figure using figure() method.
- Create x and y data points using numpy.
- Get the current axis.
- Add text to the axes using text() method.
- Add an animate method that can be used to make an animation by repeatedly calling a function.
- To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt, animation plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() x = np.linspace(-10, 10, 1000) y = np.sin(x) plt.plot(x, y) ax = plt.gca() ax.text(0.5, 1.100, "y=sin(x)", bbox={'facecolor': 'red', 'alpha': 0.5, 'pad': 5}, transform=ax.transAxes, ha="center") def animate(frame): ax.text(0.5, 1.100, "y=sin(x), frame: %d" % frame, bbox={'facecolor': 'red', 'alpha': 0.5, 'pad': 5}, transform=ax.transAxes, ha="center") ani = animation.FuncAnimation(fig, animate, interval=100, frames=10, repeat=True) plt.show()
Output
- Related Articles
- How to put the plot title inside the plot using ggplot2 in R?
- How to plot multiple histograms on same plot with Seaborn using Matplotlib?
- Animation using Matplotlib with subplots and ArtistAnimation
- How to create a plot title with unicode characters using ggplot2 in R?
- How to write the plot title in multiple lines using plot function in R?
- Increase the distance between the title and the plot in Matplotlib
- How to make a 4D plot with Matplotlib using arbitrary data?
- How to plot collections.Counter histogram using Matplotlib?
- How to plot with xgboost.XGBCClassifier.feature_importances_ model? (Matplotlib)
- Creating 3D animation using matplotlib
- How to plot with multiple color cycle using cycler property in Matplotlib
- How do I make the width of the title box span the entire plot in Matplotlib?
- How to stop unwanted UIButton animation on title change?
- How to plot MFCC in Python using Matplotlib?
- How to plot events on time using Matplotlib?

Advertisements