From: John Hunter <jdh2358@gm...> - 2011-10-15 15:56:59
On Sat, Oct 15, 2011 at 10:39 AM, <josef.pktd@...> wrote:
> I'm building plots in stages using several different functions. Since
> the figure contains all information, I don't hand handles to
> individual elements around.
> What's the best way to check for a specific plot element? using
> isinstance, or are there specific attributes that could be checked?
Checkout out Artist.findobj
Artist is the base class for everything in a matplotlib figure, the
Figure, Axes, Axis, Text, Line2D, Polygon, etc, all derive from
Artist, so you can call this method on any mpl object to recursively
search for objects of a given type. By recursive, I mean search the
objects children, their children, etc. See also
for more info on the artist hierarchy.
But for your specific example, each axes has an `images` attribute,
which is a list of images it contains (this is detailed in the artist
tutorial linked above, so you could simplify your code with something
images = np.concatenate([ax.images for ax in fig.axes])