Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 266be12

Browse files
authored
Merge pull request #19533 from timhoffm/doc-animated
Clarify the animated property and reword blitting tutorial a bit
2 parents 5ad390d + 84a8b71 commit 266be12

File tree

4 files changed

+36
-23
lines changed

4 files changed

+36
-23
lines changed

lib/matplotlib/artist.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,15 @@ def set_visible(self, b):
10041004

10051005
def set_animated(self, b):
10061006
"""
1007-
Set the artist's animation state.
1007+
Set whether the artist is intended to be used in an animation.
1008+
1009+
If True, the artist is excluded from regular drawing of the figure.
1010+
You have to call `.Figure.draw_artist` / `.Axes.draw_artist`
1011+
explicitly on the artist. This appoach is used to speed up animations
1012+
using blitting.
1013+
1014+
See also `matplotlib.animation` and
1015+
:doc:`/tutorials/advanced/blitting`.
10081016
10091017
Parameters
10101018
----------

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,8 +2930,8 @@ def draw_artist(self, a):
29302930
"""
29312931
Efficiently redraw a single artist.
29322932
2933-
This method can only be used after an initial draw which caches the
2934-
renderer.
2933+
This method can only be used after an initial draw of the figure,
2934+
because that creates and caches the renderer needed here.
29352935
"""
29362936
if self.figure._cachedRenderer is None:
29372937
raise AttributeError("draw_artist can only be used after an "

lib/matplotlib/figure.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,9 +2666,10 @@ def draw(self, renderer):
26662666

26672667
def draw_artist(self, a):
26682668
"""
2669-
Draw `.Artist` instance *a* only.
2669+
Draw `.Artist` *a* only.
26702670
2671-
This can only be called after the figure has been drawn.
2671+
This method can only be used after an initial draw of the figure,
2672+
because that creates and caches the renderer needed here.
26722673
"""
26732674
if self._cachedRenderer is None:
26742675
raise AttributeError("draw_artist can only be used after an "

tutorials/advanced/blitting.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,39 @@
11
"""
2-
=================
3-
Blitting tutorial
4-
=================
2+
==================================
3+
Faster rendering by using blitting
4+
==================================
55
6-
'Blitting' is a `standard technique
6+
*Blitting* is a `standard technique
77
<https://en.wikipedia.org/wiki/Bit_blit>`__ in raster graphics that,
88
in the context of Matplotlib, can be used to (drastically) improve
99
performance of interactive figures. For example, the
1010
:mod:`~.animation` and :mod:`~.widgets` modules use blitting
1111
internally. Here, we demonstrate how to implement your own blitting, outside
1212
of these classes.
1313
14-
The source of the performance gains is simply not re-doing work we do
15-
not have to. If the limits of an Axes have not changed, then there is
16-
no need to re-draw all of the ticks and tick-labels (particularly
17-
because text is one of the more expensive things to render).
14+
Blitting speeds up repetitive drawing by rendering all non-changing
15+
graphic elements into a background image once. Then, for every draw, only the
16+
changing elements need to be drawn onto this background. For example,
17+
if the limits of an Axes have not changed, we can render the empty Axes
18+
including all ticks and labels once, and only draw the changing data later.
1819
19-
The procedure to save our work is roughly:
20+
The strategy is
2021
21-
- draw the figure, but exclude any artists marked as 'animated'
22-
- save a copy of the RBGA buffer
22+
- Prepare the constant background:
2323
24-
In the future, to update the 'animated' artists we
24+
- Draw the figure, but exclude all artists that you want to animate by
25+
marking them as *animated* (see `.Artist.set_animated`).
26+
- Save a copy of the RBGA buffer.
2527
26-
- restore our copy of the RGBA buffer
27-
- redraw only the animated artists
28-
- show the resulting image on the screen
28+
- Render the individual images:
2929
30-
thus saving us from having to re-draw everything which is _not_
31-
animated. One consequence of this procedure is that your animated
32-
artists are always drawn at a higher z-order than the static artists.
30+
- Restore the copy of the RGBA buffer.
31+
- Redraw the animated artists using `.Axes.draw_artist` /
32+
`.Figure.draw_artist`.
33+
- Show the resulting image on the screen.
34+
35+
One consequence of this procedure is that your animated artists are always
36+
drawn on top of the static artists.
3337
3438
Not all backends support blitting. You can check if a given canvas does via
3539
the `.FigureCanvasBase.supports_blit` property.

0 commit comments

Comments
 (0)