I have noticed that there are 10 entries made to the
> 'patches'-data for every bargraph I add. Can you explain
> this - and/or possibly direct me to a page to read up more
> about "_patches".
Sure. There are only a few types of objects in matplotlib that appear
on the canvas: lines, patches, text and images. patches are things
that take up area, like circles and rectangles; the term is borrowed
from matlab. Commands like scatter, hist and bar instantiate the kind
of patch you need (eg Rectangle or RegularPolygon, both of which
derive from the Patch base class in matplotlib.patches) and add it to
the axes via Axes.add_patch. The list of patches that have been added
to the Axes are stored in a (private) variable self._patches which was
not intended to be manipulated by the user (hence the leading
underscore and my reference to the solution as a hack).
The question is: for dynamic graphs, what is the proper interface to
allow you to control, clear, etc, the patches that have been created?
The typical way one does dynamic graphs is to fix the objects (be they
lines, text or patches) and change the data attributes of those
objects (eg x and y locations, height). But your is a special case
because there is a fair amount of logic involved in getting the
attributes right for stacked bar graphs so it is probably easier to
clear the previous patches and add new ones.
Would it suffice for you if there was an axes method clear_patches
that simply removed all the previous patches you instantiated? The
reason I ask is because it is not good practice to write scripts
around private attributes which may disappear in a month.