我正在使用 PyLaTeX 自动生成报告文件。该报告将填充 matplotlib 图,我希望它们准确地放置在代码所说的位置。通常在 Latex 中,我会使用 [h] 后缀甚至 [H],但是在这里,无论我放在什么位置,它都不起作用(我的意思是地块没有放在我想要的位置)。
这是我的代码:
from pylatex import Document, Section, Subsection, Command, Figure
from pylatex.utils import italic, bold, NoEscape
import matplotlib.pyplot as plt
plt.style.use('ggplot')
import numpy as np
x = np.linspace(-np.pi/2, np.pi/2,100)
y = np.sin(x)
plt.plot(x,y)
doc = Document('Test')
doc.preamble.append(Command('title', 'Test PyLaTex'))
doc.preamble.append(Command('author', 'Mehdi'))
doc.preamble.append(Command('date', NoEscape(r'\today')))
doc.append(NoEscape(r'\maketitle'))
with doc.create(Section('Premiere Section')):
doc.append('Premiers resultats \n')
doc.append('Second resultats')
with doc.create(Section('Deuxieme section')):
doc.append('Premiers res 2')
with doc.create(Figure(position = 'htbp')) as fig:
fig.add_image('m.jpg')
fig.add_caption('Celui qui a tout fait')
with doc.create(Figure(position = 'htbp')) as plot:
plot.add_plot()
plot.add_caption('Avec matplolib')
with doc.create(Section('Troisieme')):
doc.append('test image position')
with doc.create(Section('Conclusion')):
doc.append('Iz practical')
doc.generate_pdf(clean_tex = False)
doc.generate_tex()
谢谢 !