How would I include a figure from python
in LaTeX, in order to use the same font in the text and to adjut the size.
If you can include the code that would be great.
Sorry, if my question is a bit simple.
The last two lines
mpl.use("pgf")
mpl.rcParams.update(pgf_with_latex)
Are they ment to be in python
code?
If so, what package need to be used with?
Best Answer
If you use
matplotlib
you can use something like the following:Change the
your-width
andyour-height
in the above to the desired dimensions in inch. To the preamble add anything you need to reproduce the look of your document (e.g.r"\usepackage{lmodern}
if you uselmodern
). After that you should be able to usesavefig('name.pdf')
to save the plot as a pdf and import it into LaTeX. If everything in the above was set correctly it should look like perfectly belonging to your document.If you don't want to adapt your preamble here every time you can as well use
savefig(name.pgf)
and include the resulting file in your document via\input
. This way you don't have to use your actual preamble in Python as the font is set by the TeX interpreter. But notice that this way compilation of your document takes a lot more time than if you include a pdf.You can create a new figure with custom size with
plt.figure(figsize=[width,height])
(this way you don't have to update thercParams
with the correct size).