[Matplotlib-users] What is Artist._animated used for in Matplotlib

Yuri Sukhov yuri.sukhov at gmail.com
Tue Feb 7 14:15:47 EST 2017


Hi Thomas,

Thank you for your response. Is it possible to find somewhere
documentation with the details on how drawing is done in Matplotlib?
Or maybe you can shed some light on this? Of course source code is
here and I am reading it, but without knowing of what are the major
steps of the process, it takes a lot of time to take all parts
together.

I looked at the _AxesBase.draw() method, and I can see that, if
_animated is set for the artist, than it's excluded from rasterization
(not sure if that is the right term). That does not tell me much,
because I am not aware of the whole drawing process. I am not even
sure, when is this draw() method called? It seems to me that
_blit_draw() from Animation class calls a.axes.draw_artist(a), but
that is a different method and it does not check _animation property
for the artist.


On Mon, Feb 6, 2017 at 11:03 PM, Thomas Caswell <tcaswell at gmail.com> wrote:
> See
> https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes/_base.py#L2355
>
> It is used to exclude the 'animated' artists from the normal draw method
> which greatly simplifies getting a clean background image.
>
> Tom
>
> On Mon, Feb 6, 2017 at 3:15 PM Yuri Sukhov <yuri.sukhov at gmail.com> wrote:
>>
>> Hi all,
>>
>> I am writing my own Animation class for Matplotlib in order to use
>> event-based animation and it's unclear how Artist._animated and associated
>> set_animated() function affect rendering.
>>
>> My animation should use blitting and I took existing FuncAnimation class
>> as a reference for my implementation. In this class _init_draw and
>> _draw_frame methods, among other things, set _animated = True for each
>> artist in self._drawn_artists if blitting is enabled:
>>
>> for a in self._drawn_artists:
>>     a.set_animated(self._blit)
>>
>> What is the reason for this operation? In what cases Artist._animated is
>> used, and how it affects rendering with or without blitting? I have tested
>> my implementation and I don't see any difference in behaviour with or
>> without set_animated():
>>
>> class DataAnimation(Animation):
>>     def __init__(self, fig, *args, **kwargs):
>>         super(DataAnimation, self).__init__(fig,
>> event_source=event_source, *args, **kwargs)
>>
>>     def new_frame_seq(self):
>>         return itertools.count()
>>
>>     def _init_draw(self):
>>         self._drawn_artists = plot.init()
>>         for artist in self._drawn_artists:  # <- do we need this?
>>             artist.set_animated(self._blit)
>>
>>     def _draw_frame(self, frame_data):
>>         self._drawn_artists = plot.updated_artists
>>         for artist in self._drawn_artists:  # <- do we need this?
>>             artist.set_animated(self._blit)
>>
>> Thanks!
>>
>> Yuri.
>> _______________________________________________
>> Matplotlib-users mailing list
>> Matplotlib-users at python.org
>> https://mail.python.org/mailman/listinfo/matplotlib-users


More information about the Matplotlib-users mailing list