【发布时间】:2014-03-20 04:43:32
【问题描述】:
我有一个项目,它使用 matplotlib 生成一组图表并将每个图表导出为单独的 PNG 文件。客户还希望将一组图表输出为单个 PDF 文件。我们已经成功地使用 PIL Image 和 matplotlib PdfPages 在单独的页面上导入每个 PNG 并导出多页 PDF,但 PDF 输出质量是不可接受的。如果我在 savefig 中使用 dpi=100 以外的任何内容,则输出为空白。有关如何以更高的光栅分辨率导出 PDF 的任何建议?
pp = PdfPages(filepath+'Treatment Zone Charts.pdf')
for file in os.listdir(filepath):
if "Treatment Zone Charts" in file and file.endswith(".png"):
print filepath+file
#read PNG image
im = Image.open(filepath+'/'+file)
im = im.resize((1100,850),Image.ANTIALIAS)
im = np.array(im).astype(np.float) / 255
# Create a figure with size w,h tuple in inches
fig = Figure(figsize=(11,8.5))
# Create a canvas and add the figure to it.
canvas = PDF_FigureCanvas(fig)
#add image to plot
fig.figimage(im, 0, -220, zorder = 1)
# Save the Plot to the PDF file
pp.savefig(fig, dpi=100)
#close the PDF file after the last plot is created
pp.close()
【问题讨论】:
标签: python pdf matplotlib