1

It appears as though the default behavior of savefig in PdfPages will save a vectorized image (each data point is an object) leading to large file size and slow loading/rendering. Can we save a rasterized image (e.g. PNG) so that it renders quickly?

This is what I'm doing now, that results in vector images:

plt.ioff()
with PdfPages(foutname) as pdf:
  for row in df.itertuples():
    data = ReadFile(df.fname)
    plt.clf()
    plt.plot(data['time'], data['voltage'], 'bo')
    pdf.savefig()
    plt.close()

Thanks.

user3450049
  • 825
  • 1
  • 10
  • 20

1 Answers1

-1

I guess it is sufficient to set rasterized=True:

plt.plot(data['time'], data['voltage'], 'bo', rasterized=True)
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • 1
    Please notify me if this isn't working. It should. Wondering why people downvoted. – ImportanceOfBeingErnest Oct 25 '17 at 12:34
  • For future visitors, here are a couple of references to check out: https://matplotlib.org/gallery/misc/rasterization_demo.html https://stackoverflow.com/questions/10049248/how-to-better-rasterize-a-plot-without-blurring-the-labels-in-matplotlib – eclark Aug 16 '19 at 19:47