17

I have some complex graphs made using matplotlib. Saving them to a pdf using the savefig command uses a vector format, and the pdf takes ages to open. Is there any way to save the figure to pdf as a raster image to get around this problem?

geometrikal
  • 3,195
  • 2
  • 29
  • 40
  • If you want to save to different format within matplotlib just use savefig("filename.png") to save to png raster. If you want to continue saving to PDF and then convert I agree with Gael to use Imagemagick – Trond Kristiansen Apr 11 '11 at 08:34

2 Answers2

20

You can force individual figure elements to be rasterized like this:

text(1,1,'foobar',rasterized=True)
Jouni K. Seppänen
  • 43,139
  • 5
  • 71
  • 100
3

Not that I know, but you can use the 'convert' program (ImageMagick') to convert a jpg to a pdf: `convert file.jpg file.pdf'.

Gael Varoquaux
  • 2,466
  • 2
  • 24
  • 12