I am trying to make plots, using PyPlot, that have latex equations. Does anyone know how to change the font of the default latex render in PyPlot ? Right now I am using the following:
The L"Linear" form makes PyPlot treat the whole string as a math expression (as if surrounded by dollar signs in \LaTeX). Either use "Linear" or (to embed normal text in a math expression) L"\mathrm{Linear}".
This is not iron-clad: if you specify rc("font",style="italic"), you may not be able to get away from italics at all.
If you don’t want an equation, you just shouldn’t use L"…" at all. Just use an ordinary string.
All L"…" does is allow you to enter equations without having to insert tons of backslash escapes, and to allow you to optionally omit the .... There is no reason to use it if you don’t want an equation.
Well - except to match fonts. In this case just use L"\text{blah}" or possibly L"{\rm blah}" - I didn’t test this but something along those lines will work
Continuing the thread: I would like to change the label fonts to the default (Computer Modern, it appears) font of Latex.
I am trying something like this:
using LaTeXStrings
using PyPlot
x = [ 0, 1 ]
y = [ 0, 1 ]
rc("font",family="serif")
xlabel(L"x")
ylabel(L"y")
plot(x,y)
savefig("plot.pdf")
It doesn´t matter which font family I set, the output is always the same, and the font of the “x” looks like DejaVu Sans. I searched quite a bit how to do that and tried many things, but with no luck. A minimal working example of a font change would be of great help!
Thank you.
EDIT: I noticed now that that is changing the font of the tick numbers, but not the font of the labels.
Adding my method for those also using Seaborn on top of matplotlib:
using PyPlot; using LaTeXStrings; using PyCall; @pyimport seaborn as sns;
rc_mod = Dict("mathtext.default" => "regular",
"pgf.preamble" => [raw"\usepackage[detect-all,locale=DE]{siunitx}"])
sns.set(rc=rc_mod )
Still can’t figure out how to load in custom latex packages though…