python為字型新增上下標

Mr.Jcak發表於2019-04-19

新增上標:^

新增下標:_

舉例:

import numpy as np
import matplotlib.pyplot as plt

t = np.linspace(0, 10, 1000)
y = np.sin(t)
plt.plot(t, y)
plt.xlabel('a/${m_2}$',fontdict={'weight': 'normal', 'size': 15})
plt.show()

效果:

如果去掉斜體格式:

import numpy as np
import matplotlib.pyplot as plt

t = np.linspace(0, 10, 1000)
y = np.sin(t)
plt.plot(t, y)
plt.xlabel('a/$\mathregular{m_2}$',fontdict={'weight': 'normal', 'size': 15})
plt.show()

 效果:

新增上標:

import numpy as np
import matplotlib.pyplot as plt

t = np.linspace(0, 10, 1000)
y = np.sin(t)
plt.plot(t, y)
plt.xlabel('a/$\mathregular{m^2}$',fontdict={'weight': 'normal', 'size': 15})
plt.show()

相關文章