Reputation: 121
I'm currently starting to write up my PhD thesis and am now in the middle of setting up everything. One of the objectives is to use the same font in schemes and figures as in the text. However, when selecting bold text in matplotlib the fonts are not matching the latex font.
At the moment I am using these rc_params:
new_rc_params = {'text.usetex': True,
'svg.fonttype': 'none',
'text.latex.preamble': r'\usepackage{libertine}',
'font.size': 10,
'font.family': 'Linux Libertine',
'mathtext.fontset': 'custom',
'mathtext.rm': 'libertine',
'mathtext.it': 'libertine:italic',
'mathtext.bf': 'libertine:bold'
}
mpl.rcParams.update(new_rc_params)
This will lead to the right font in normal text as far as I can tell.
Matplotlib:
LaTeX comparison:
If I now, however, select bold text in matplotlib via:
$\mathbf{TS_{I,II}}$
I get the following output:
For comparison the bold and normal pure LaTeX output:
Now, I have read that for better math support in LaTeX I should add \usepackage[libertine]{nextxmath}
to text.latex.preamble
in rc_params
. If I do this, matplotlib generates the following output:
Which still is not the same font as I get from my LaTeX document. Does anyone have any ideas what I could additionally change to make the fonts identical?
(Can't post inline images...)
Upvotes: 2
Views: 1016
Reputation: 121
I figured it out, with the help of the comment from @Patol75
So it is indeed rather a "pythonic" problem. For some reason if you try to use:
$\textbf{...}$
in a matplotlib label, it gets rendered like the following:
For some reason that I did not look into further, LaTeX commands starting with \b...
spit out an error. Which prevented the easy use of \bm
. However, if one uses an r'
in front of the command everything works fine. Therefore, one can use:
r'\textbf{TS$_{\textbf{I,II}}$}'
This produces the correct/expected output:
matplotlib5
Upvotes: 0