import matplotlib.pyplot as plt
from matplotlib import rcParams
config = {
"font.family": 'serif',
"font.size": 15,
"mathtext.fontset": 'stix',
"font.serif": ['SimSun'],
}
rcParams.update(config)
x = [1, 2, 3, 4, 5]
y = x
z = [2, 4, 6, 8, 10]
fig = plt.figure(figsize=(5, 4))
plt.rcParams['xtick.direction'] = 'in'
plt.rcParams['ytick.direction'] = 'in'
ax1 = fig.add_subplot(111)
ax1.plot(x, y, color='black', label='正比例')
ax1.plot(x, z, '--', color='black', label='y = 2x')
ax1.legend()
plt.xlabel('横坐标')
plt.ylabel('纵坐标')
plt.title(r'线性函数')
plt.show()
参考文章
【1】知乎原文
【2】添加链接描述