matplotlib remove drawn text

Solutions on MaxInterview for matplotlib remove drawn text by the best coders in the world

showing results for - "matplotlib remove drawn text"
Domenico
19 Sep 2020
1# instead of drawing your text like this
2fig.text(0, 0, 'My text')
3
4# you can do
5textvar = fig.text(0, 0, 'My text')
6
7# If you've lost the references, though, all the text objects
8# can be found in the texts attribute:
9fig.texts # is a list of Text objects
10
11# In version 1.3.1, doing textvar.remove() generates a NotImplementedError
12# (apparently fixed in 1.4). However, you can get around that to some
13# degree by setting the visibility to False.
14
15for txt in fig.texts:
16    txt.set_visible(False)
17    
18