Python drawing adds superscript and subscript to font

  • In mathematical formulas, superscripts are ^denoted by , and subscripts are _denoted by
  • In Python drawing, add dollar signs on both sides of the superscript and subscript $, and if only one symbol needs to be subscripted, it does not need to be {}enclosed in curly braces. If there are many symbols that require subscripts and subscripts, they must be {}enclosed in curly braces
import numpy as np
import matplotlib.pyplot as plt
 
x1 = np.linspace(0, 10, 50)
x2 = np.linspace(0, 15, 100)
y1 =np.sin(x1)
y2 =np.cos(x2)
# 设置下标
plt.plot(x1,y1,label='sin$_x$')
# 设置上标
plt.plot(x2,y2,label='cos$^x$')
# 设置上标,多于1个符号,需添加括号{}
plt.xlabel('2020$^{2021}$')
plt.legend()

insert image description here
Learning link:

Guess you like

Origin blog.csdn.net/weixin_45913084/article/details/131108391