ARTICLE AD BOX
I am trying to display a LaTeX-style equation in a Matplotlib plot using a custom font (Algerian). I want both the equation and the surrounding text to use the same upright (non-italic) font. Here's a minimal example:
import matplotlib.pyplot as plt plt.rcParams['font.family'] = 'Algerian' plt.rcParams['font.weight'] = 'bold' plt.rcParams['font.size'] = 10 plt.figure() plt.text(0.1, 0.5, r"$a*ln(x)*x^2+2$", fontfamily='Algerian') plt.show()The problem is that while normal text respects the font settings, the math text does not inherit the Algerian font and also defaults to italic.
I understand that Matplotlib math text always uses the math font (Computer Modern by default). In my real application, the expressions are much more complex, which makes switching everything to plain text or using Unicode very tricky.
Is there a way to have both the custom upright font and proper LaTeX formatting in Matplotlib?
