【发布时间】:2021-12-14 01:00:36
【问题描述】:
我有一组照片,我为它们制作了标签,我想将它们直接放置在图像下方并将它们保存在 pdf 中,如此链接 https://docdro.id/4AZFIae。如您所见,有些标签在下方,有些与图片相交。我正在以下循环中制作此 pdf。我还没有弄清楚,如何设置 plt.figtext(x,y,textString...) 的位置值,以便 textString (label) 始终位于图像的正下方。我猜 x,y 取决于 textString 的行数,但我没有弄清楚关系
pdf = FPDF()
#begin of loop where I create the labels and upload the pictures
for c in range(0,15)
#...
imshow=plt.imshow(img)
#pdfFile.savefig(imshow)
plt.axis('off')
plt.title(n_id)
count = 0
textString =""
for c in range(0,c_lab):
textString += str(lab_out[c])
c += 1
textString += '\n'
strar=['hallo', 'Das ist ein Text']
textvar=plt.figtext(0.01, -1.0, textString, wrap=False, va='bottom', horizontalalignment='left', fontsize=12) #textString = Labels you can see in the pdf
plt.savefig('testplot' + str(c) +'.jpg', bbox_inches="tight")
pdf.add_page()
pdf.image('testplot' + str(c) +'.jpg')
textvar.remove()
lab_text={}
i+=1
pdf.output("yourfile.pdf", "F")
【问题讨论】:
标签: python image matplotlib pdf plot