Just pass the rasterized=True keyword to your collection constructor. Example:
col = collections.PolyCollection(<arguments>, rasterized=True)
This allows only selective rasterization of this element (for example, if you made a normal plot on top of it, it will be vectorized by default). Most commands, such as plot or imshow , can also accept the rasterized keyword. If you want to rasterize the entire drawing (including labels and annotations), this would do this:
fig = plt.figure() a = fig.add_subplot(1,1,1, rasterized=True)
(But this is not what you want, as stated in the question.)
source share