I am creating the plots and figures for my thesis using matplotlib and save them as .pgf files that I include using

    \caption{A caption}

which by default typesets all math and labels in the figure using the same fonts as in the document. But I want my plots and figures to use sans serif fonts while using palatino as the main document font.

So far I tried the following: Add mpl.rcParams["font.family"] = "sans-serif" to the plot generation code to get all the non-math text typeset in a sans serif font and to get the math in a sans serif font I used the sansmath package as follows:

% preamble
% more preamble

    \caption{A caption}


This works well for all labels and math in the figure except for greek letters. Using the option \usepackage[eulergreek]{sansmath} also doesn't help.

Does anyone have a good solution to include pgf files with all sans-serif fonts? Preferably a solution that does not require changing the matplotlib rcParams, because I might want to reuse the figures elsewhere with different formatting.


1 Answer 1


Okay, I found a solution that works well enough. Basically, the main problem was that the math fonts don't obey the surrounding font family. I.e. math that is in a paragraph typeset in sans-serif font is not typeset in sans-serif. So one needs to make sure, that math is also properly typeset in a sans family font, by adding the following to the preamble:




and keeping the mpl.rcParams["font.family"] = "sans-serif" to make the plots all sans-serif.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .