TransWikia.com

Matplotlib : Why doesn't legend font appear as Latex rendering

TeX - LaTeX Asked on June 1, 2021

Below the PDF output generated by a Python script :

example

As you can see, labels and title are correctly appearing as Latex rendering.
Excepted the fact that Latex font is not applied for legend and I don’t understand why.

Here the Python script :

rc_fonts = {
    "text.usetex": True,
}
plt.rcParams.update(rc_fonts)

fig, axes = plt.subplots()
plt.xscale('log')
plt.xlabel(r'$1/sigma$', fontsize=10, fontweight='bold')
plt.ylabel(r'FoM - GCsp + XC', fontsize=10, fontweight='bold')
plt.title(r'FoM - GCsp + XC vs 1/$sigma$ for $alpha = b_{sp}/b_{ph}$', fontsize=10, fontweight='bold')
array_z_fid = [ '0.9595', '1.087', '1.2395', '1.45', '1.688' ]
x_major = mpl.ticker.LogLocator(base = 10.0, numticks = 20)
axes.yaxis.set_major_locator(x_major)
x_minor = mpl.ticker.LogLocator(base = 10.0, subs = np.arange(1.0, 10.0)*0.1, numticks = 10)
axes.xaxis.set_minor_locator(x_minor)
axes.yaxis.set_major_locator(MaxNLocator(integer=True))

# Plot each curve
inv_sigma = 1./sigma
axes.plot(inv_sigma, FoM_final, label=r'common bias - bin : '+str(j+1)+' ; z = '+array_z_fid[j])
# Legend
axes.legend(fontsize=8, loc="best")

If someone could indicate me how to apply Latex font for legend, this would be fine.

ps : just a last remark, in my code snippet, why can’t I put $alpha = b_{text{sp}}/b_{text{ph}}$ to get sp and ph vertical subscript ?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP