{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n.. redirect-from:: /tutorials/advanced/blitting\n\n\n# Faster rendering by using blitting\n\n*Blitting* is a [standard technique](https://en.wikipedia.org/wiki/Bit_blit)_ in raster graphics that,\nin the context of Matplotlib, can be used to (drastically) improve\nperformance of interactive figures. For example, the\n:mod:`.animation` and :mod:`.widgets` modules use blitting\ninternally. Here, we demonstrate how to implement your own blitting, outside\nof these classes.\n\nBlitting speeds up repetitive drawing by rendering all non-changing\ngraphic elements into a background image once. Then, for every draw, only the\nchanging elements need to be drawn onto this background. For example,\nif the limits of an Axes have not changed, we can render the empty Axes\nincluding all ticks and labels once, and only draw the changing data later.\n\nThe strategy is\n\n- Prepare the constant background:\n\n - Draw the figure, but exclude all artists that you want to animate by\n marking them as *animated* (see `.Artist.set_animated`).\n - Save a copy of the RBGA buffer.\n\n- Render the individual images:\n\n - Restore the copy of the RGBA buffer.\n - Redraw the animated artists using `.Axes.draw_artist` /\n `.Figure.draw_artist`.\n - Show the resulting image on the screen.\n\nOne consequence of this procedure is that your animated artists are always\ndrawn on top of the static artists.\n\nNot all backends support blitting. You can check if a given canvas does via\nthe `.FigureCanvasBase.supports_blit` property.\n\n
This code does not work with the macosx backend (but does work with other\n GUI backends on Mac).