How do I make sans serif superscript or subscript text in matplotlib?
Use \mathregular
to use the font used for regular text outside of mathtext:
$\mathregular{N_i}$
Take a look here for more information.
You can do it by customizing rcParams
. If you have multiple elements to customize, you can store them as a dict
and the update the `rcParams':
params = {'mathtext.default': 'regular' }
plt.rcParams.update(params)
If you want to do a single modification, you can simply type:
plt.rcParams.update({'mathtext.default': 'regular' })
In this respect, a trivial example would be as follows:
import numpy as np
from matplotlib import pyplot as plt
x = np.linspace(1, 10, 40)
y = x**2
fig = plt.figure()
ax = fig.add_subplot(111)
params = {'mathtext.default': 'regular' }
plt.rcParams.update(params)
ax.set_xlabel('$x_{my text}$')
ax.set_ylabel('$y_i$')
ax.plot(x, y)
ax.grid()
plt.show()
You can find more information on RcParams
in the matplotlib documentation.