Sentence
@tcaswell overriding the Axes.draw method is by far the most flexible way to approach this.
However, you can use / abuse blitting to do this without subclassing Axes . Just use draw_artist every time without restoring the canvas.
There is another trick: we need a special save method, since everyone else draws a canvas before saving, which will destroy everything that we painted earlier.
Also, as tcaswell notes, calling draw_artist for each element is pretty slow, so for a lot of points, you'll want to split your input. Chunking will give significant speedup, but this method will always be slower than drawing one PathCollection .
Anyway, any of these answers should ease your memory problems. Here is a simplified example.
import numpy as np import matplotlib.pyplot as plt from matplotlib import _png from itertools import izip def main():

In addition, you may notice that the upper and left spikes are pulled. You can get around this by dragging these two spikes ( ax.draw_artist(ax.spines['top']) , etc.) before saving.
source share