Quantcast

What is Artist._animated used for in Matplotlib

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

What is Artist._animated used for in Matplotlib

Yuri Sukhov
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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What is Artist._animated used for in Matplotlib

tcaswell
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 <[hidden email]> 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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What is Artist._animated used for in Matplotlib

Yuri Sukhov
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 <[hidden email]> 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 <[hidden email]> 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
>> [hidden email]
>> https://mail.python.org/mailman/listinfo/matplotlib-users
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What is Artist._animated used for in Matplotlib

tcaswell
http://www.aosabook.org/en/matplotlib.html is a reasonable starting point, it refers to 0.96, but the core of the library has not changed much.

The very short version is that through a layer or two of in-direction when the figure is rendered, the canvas creates a renderer and pass it to `Figure.draw` which then recurses it's children calling `Artist.draw` which renders all of the artists to the canvas (which may represent a file or a bit map, which in the case of a GUI is then passed to the GUI toolkit and displayed on the screen).

`draw_artist` is a helper-method on Axes to make doing blitting work easier.  During `Axes.draw` it caches a reference to the renderer so that you can out-of-band render additional artists.  See http://matplotlib.org/api/animation_api.html#funcanimation for a much longer explanation of how this works.

Tom

On Tue, Feb 7, 2017 at 2:16 PM Yuri Sukhov <[hidden email]> wrote:
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 <[hidden email]> 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 <[hidden email]> 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
>> [hidden email]
>> https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Loading...