Closed thatlittleboy closed 7 years ago
draw
doesn't erase the old annotation. (In fact, it doesn't really do anything here.)
Calling annotate
twice just adds two annotations. This is not a bug, this is how matplotlib works. If you want to erase the annotation, the simplest thing is to clear the figure and draw a new one.
You can also call the remove
method of the old annotation: https://stackoverflow.com/questions/12222397/python-and-remove-annotation-from-figure
I am using Atom+Juno (v0.3.0), PyPlot (v 2.3.2).
Consider the following minimal example:
Running this, I obtain a figure in a window called "Figure 1 plot" as expected. Keeping the figure window open, I then make a change to the annotate argument, say:
"Figure Top Right" -> "Figure New Right"
and run theannotate(...)
block.Instead of obtaining an updated/refreshed figure with "Figure New Right" on the top right of the figure, I see that "Figure New Right" is printed over the old "Figure Top Right", like so:
How should I set up my code so that the PyPlot figure updates, not prints over the old settings? Note that I know that I can run the whole code again (to generate a new figure window, from scratch), but that becomes a hassle when my plotting code is very long, and unnecessary imo.
Ninja edit:
According to the matplotlib documentation, the
draw()
function "redraw(s) the current figure. This is used to update a figure that has been altered, but not automatically re-drawn".Even adding
below the
annotation
block from before, the result is still the same. I'm probably misunderstanding the use of thedraw
function here then..