- 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 refresh text in Matplotlib?
To refresh text in Matplotlib, 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.
- Add text to the axes.
- Write customized method to update text based on the keys "z" and "c".
- Bind the function action with key_press_event.
- Draw the canvas that contains the figure.
- Animate the figure with texts.
- To display the figure, use show() method.
Example
from matplotlib import pyplot as plt, animation plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() text = ax.text(.5, .5, 'First Text') def action(event): if event.key == "z": text.set_text("zoom") elif event.key == "c": text.set_text("cool") fig.canvas.mpl_connect('key_press_event', action) fig.canvas.draw() animation = animation.ArtistAnimation(fig, [(text,)]) plt.show()
Output
- Related Articles
- How to animate text in Matplotlib?
- How to autosize text in matplotlib Python?
- How to add bold annotated text in Matplotlib?
- How to refresh a page in Firefox?
- How to annotate a heatmap with text in Matplotlib?
- How to add text inside a plot in Matplotlib?
- How to curve text in a polar plot in matplotlib?
- How to add a text into a Rectangle in Matplotlib?
- How to annotate several points with one text in Matplotlib?
- How to implement Android Pull-to-Refresh?
- How to Automatically Refresh a Pivot Table in Excel?
- How to refresh Activity when IntentService is finished in android?
- How to refresh Singleton class every one hour in android?
- Automatically position text box in Matplotlib
- Adjusting Text background transparency in Matplotlib

Advertisements