Take the 2-minute tour ×

Let's say I make a series of AnnotationBbox'es in matplotlib through a for loop, like this:

 for city in cities:
     x, y = self.map(city[1], city[0])

     ab = AnnotationBbox(imagebox, [x,y],
                                xybox=(0, 0),
                                boxcoords="offset points",

In this example, I've created a series of AnnotationBBoxes, and stored them in a list called self.locationImages. Then I go through the self.locationImages in a loop, and remove each one by doing this:

    for image in self.locationImages:

Is there a way to remove all the artists, without having to go through a loop? Or to remove all artists, and lines completely, without having to remove the axes or the figure?

I'm plotting points on a map, and I need the map to stay. I'm doing zoom ins and outs, but during zoom ins and outs, I need to remove everything and replot. I'm working with a large data set and doing iterations is an expensive action

share|improve this question
using set_visible might be a better option than removing the artists. matplotlib.org/api/… You will still have to trigger a re-draw, but you won't have to set up and tear down the artists. –  tcaswell Jul 26 '13 at 20:14

1 Answer 1

From matplotlib's pyplot interface, you can pyplot.cla() to clear an entire axis and pyplot.clf() to clear an entire figure.

share|improve this answer
Those are axes and figure level functions as well-> ax.cla() and fig.clf(), but they will remove everything, including the map the OP wants to keep. –  tcaswell Jul 26 '13 at 20:11
@tcaswell whoops. not sure how i missed that! –  Paul H Jul 27 '13 at 0:16

Your Answer


