From http://matplotlib.org/examples/pylab_examples/demo_agg_filter.html