Each text object that you add with the text() function is appended to a list called "texts" that is an attribute of the axes object. So, to remove the last text object you added, you can do:
If what you want to do is change the contents but not the position, you can do:
If you want to change the position, you can do:
Note that in the set_position method, unlike the text() function, the position is specified as an (x,y) tuple; the parentheses are required.
Or you can just shift one coordinate:
If you want to change the first text object, then of course you would use texts instead of texts[-1], etc.
There is an alternative pylab function for setting properties that takes care of redrawing automatically. Here is an example:
setp(gca().texts[-1], 'fontsize', 15) # Matlab-style
setp(gca().texts[-1], fontsize=17) # nicer style
If you are going to want to experiment with the properties of your text object, then grab a reference to it when you create it, like this:
tt = text(6,7,'another one')
That way you don't have to keep typing "gca().texts[-1]".
Aaron Hoover wrote:
Matplotlib is great. Between numpy, scipy, and matplotlib, I'm almost completely weaned myself off of Matlab (just need to rewrite a bunch of m-files in Python).
My question is, is there an easy way to remove text that's been added with the text() function from a plot (like if I make a mistake in the text or its position)? I've thought about adding a long string of spaces in the same location, but haven't tried it yet. Is there an easier way like a clear() function or some other method I may have missed?
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
Matplotlib-users mailing list