Matplotlib - How to plot a high resolution graph?

前端 未结 6 1707
情深已故
情深已故 2020-12-07 13:16

I\'ve used matplotlib for plotting some experimental results (discussed it in here: Looping over files and plotting. However, saving the picture by clicking right to the ima

6条回答
  •  北海茫月
    2020-12-07 13:29

    For future readers who found this question while trying to save high resolution images from matplotlib as I am, I have tried some of the answers above and elsewhere, and summed them up here.

    Best result: plt.savefig('filename.pdf')

    and then converting this pdf to a png on the command line so you can use it in powerpoint:

    pdftoppm -png -r 300 filename.pdf filename

    Less successful test #1: plt.savefig('filename.png', dpi=300)

    This does save the image at a bit higher than the normal resolution, but it isn't high enough for publication or some presentations. Using a dpi value of up to 2000 still produced blurry images when viewed close up.

    Less successful test #2: plt.savefig('filename.pdf')

    This cannot be opened in Microsoft Office Professional Plus 2016 (so no powerpoint), same with Google Slides.

    Less successful test #3: plt.savefig('filename.svg')

    This also cannot be opened in powerpoint or Google Slides, with the same issue as above.

    Less successful test #4: plt.savefig('filename.pdf')

    and then converting to png on the command line:

    convert -density 300 filename.pdf filename.png

    but this is still too blurry when viewed close up.

    Less successful test #5: plt.savefig('filename.pdf')

    and opening in GIMP, and exporting as a high quality png (increased the file size from ~100 KB to ~75 MB)

    Less successful test #6: plt.savefig('filename.pdf')

    and then converting to jpeg on the command line:

    pdfimages -j filename.pdf filename

    This did not produce any errors but did not produce an output on Ubuntu even after changing around several parameters.

提交回复
热议问题