[Matplotlib-users] Problem animating a histogram and movie at the same time

Ryan May rmay31 at gmail.com
Wed Jun 14 18:18:39 EDT 2017


On Wed, Jun 14, 2017 at 1:43 PM, David J Pine <djpine at gmail.com> wrote:

> I am having a problem animating a histogram and movie at the same time
> using matplotlib.animation.ArtistAnimation.
>
> The first program below, which makes an animated histogram using the "bar"
> routine works fine.  If I substitute the two lines commented out for the
> two lines preceding those lines, it still works fine (using "plot" instead
> of 'bar").  For reasons that are not clear to me, I need make a
> list (ims) for animation for the histogram using the "bar" routine, and a
> list of lists for animation of the simple "plot" routine.
>
> There is a more serious problem with the second routine where I
> simultaneously animate a sequence of images using imshow and also try to
> make an animated histogram.  It works fine if I plot the "histogram" using
> the "plot" routine but does not work if I use the "bar" routine.  Can
> someone offer some help?
>
> I am running these on OSX 10.12.5, Python 3.5.2 or Python 3.6.1, and
> matplotlib 2.0.0 or 2.0.2
>


David,

Thanks for the complete examples, it made figuring this out really quick.
ArtistAnimation expects to be given a list of lists (or tuples), where the
inner collection contains all of the artists that should be rendered for a
given frame. In the case of bar, it returns a BarCollection object (which I
just learned), is a subclass of tuple. This explains why it works (by
itself), when directly appended to the list given to ArtistAnimation; the
BarCollection acts as the collection of artists that ArtistAnimation is
expecting. In the case of the second example, ArtistAnimation is being
given a list([BarCollection, Image]); because BarCollection isn't actually
an Artist, it causes the problem. What you should try is:

ims.append([im1] + list(im2))

This converts the BarCollection to a list of the individual Bar artists,
and adds to the list containing the image; ArtistAnimation can understand
this and it seems to work fine on my system.

Ryan

-- 
Ryan May
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20170614/232e5864/attachment.html>


More information about the Matplotlib-users mailing list