I would like to include a filled contour plot to a pdf document (for example a TeX document).
Currently I am using pyplot
s contourf
, and saving to pdf
with pyplot
s savefig
. The problem with this is that the size of the plots becomes rather big as compared to a high resolution png
.
One way to reduce the size is of course to reduce the number of levels in the plot, but too few levels gives a poor plot. I'm searching for a simple way to for example let the colors of the plot be saved as a png, with the axes, ticks etc. to be saved vectorized.
You can do this using the
Axes
optionset_rasterization_zorder
.Anything with a
zorder
less than what you set that to be will be saved as rasterized graphics, even when saving to a vector format likepdf
.For example:
You can see this matplotlib example for more background info.
As pointed out by @tcaswell, to rasterise just one artist without having to affect its
zorder
, you can use.set_rasterized
. However, this doesn't appear to be an option withcontourf
, so you would need to loop over thePathCollections
created bycontourf
andset_rasterized
on each of them. Something like this: