

- 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
How can you clear a Matplotlib textbox that was previously drawn?
To clear a Matplotlib textbox that was previously drawn, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create x and y data points using numpy.
- Plot x and y using plot() method.
- Place characters token on the plot.
- To clear the text, use text.remove(), where text is a returned artist.
- To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() x = np.linspace(-10, 10, 100) y = np.sin(x) ax.plot(x, y) text = fig.text(0.5, 0.96, "$y=sin(x)$") #text.remove() plt.show()
Output
Now, uncomment the line "text.remove()" and execute the code again. It will produe the following output.
- Related Questions & Answers
- How can I clear text of a textbox using Python Selenium WebDriver?
- What was the time when you felt a person was actually a shrewd one?
- Can you show some pictures that prove you a skilled photographer?
- What was your dream and how did you achieve it?
- How do you set, clear, and toggle a bit in C/C++?
- How to output JavaScript into a Textbox?
- How can I clear console using C++?
- How do you write a method in Java that can print object in array?
- What are the things that you can do normally when you are pregnant?
- How can I tell when a MySQL table was last updated?
- How can I clear or empty a StringBuilder in Java.
- How can I write unit tests against code that uses Matplotlib?
- How can you have a satisfied life?
- How to ignore a previously committed file in Git repository?
- How to clear the memory completely of all Matplotlib plots?
Advertisements