import numpy as np
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
plt.rcParams['font.family'] = ['SimSun', 'Times New Roman']
plt.rcParams.update({'font.size': 15})
# 导入x和y
data = np.loadtxt('data.txt')
x = data[:, 0] # 第一列是位置
y = data[:, 1:] # 除第一列之外
# 设置中文字体
font = FontProperties()
font.set_family('SimSun') # 设置中文字体为宋体
plt.rcParams['font.family'] = font.get_family()
# 设置数字字体
plt.rcParams['font.serif'] = ['Times New Roman']
fig, ax = plt.subplots()
ax.stackplot(x, y.transpose(),
labels=['1', '2'], alpha=0.8)
ax.legend(loc='upper left')
ax.set_xlim(left=0, right=12) # 设置x轴起点和终点
ax.set_title('1')
ax.set_xlabel('1')
ax.set_ylabel('2')
plt.show()