How to use Arial font for LaTeX equation in Matplotlib

Viewed 366

I want to set every font including normal text and LaTeX equation (text enclaved by $ symbols) to be Arial because the journal which I am preparing to submit a paper made such a guideline regarding font inside figure.

I installed TexLive 2021 and added mpl.rc('text', usetex=True) like the code written below. However, unfortunately, Arial font is not applied to every text.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['mathtext.rm']='Arial'
mpl.rcParams['mathtext.it']='Arial:italic'
mpl.rcParams['mathtext.bf']='Arial:italic:bold'
mpl.rc('font', family='Arial')
mpl.rc('text', usetex=True)
mpl.rcParams['axes.unicode_minus']=False

fig=plt.figure(figsize=(10, 10))

x, y=np.arange(10), np.arange(10)
plt.scatter(x, y, s=100, color="r")
plt.xlabel(r"TEST: $\phi\times\eta$", fontsize=25, labelpad=10)
plt.ylabel(r"TEST: $\varepsilon\times\zeta$", fontsize=25, labelpad=10)
plt.xticks(fontsize=20)
plt.yticks(fontsize=20)

plt.text(x=1, y=6, s=r"TEST: $x\times y$", fontsize=30)

plt.show()

usetex

Instead, if I delete the option mpl.rc('text', usetex=True), Arial font is well applied to non-LaTeX texts, but LaTeX equations are not affected and default font for LaTeX equation is used. How can I apply Arial (or other custom font) to LaTeX text in matplotlib? nousetex

0 Answers
Related