import matplotlib.pyplot as plt
# 准备数据
x = [1, 2, 3, 4, 5] # x轴数据
y= [2, 4, 6, 8, 10] # y轴数据
# 创建折线图 plt.plot(x, y, marker='o', linestyle='-', color='b')
# 添加注释 for i in range(len(x)): plt.annotate(f'({x[i]}, {y[i]})', (x[i], y[i]), textcoords="offset points", xytext=(0,10), ha='center')
# 设置图表标题和坐标轴标签
plt.title("折线图")
plt.xlabel("X轴")
plt.ylabel("Y轴")
# 显示网格线
plt.grid(True)
# 显示图表
plt.show()