import matplotlib.pyplot as plt
from matplotlib import cm
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False
# 假设ans_sum是一个包含多个列表的列表
ans_sum = [
[], # 用于索引0的虚拟列表(在你的原始代码中未使用)
[-1, 2, 3, 4], # 索引1的示例数据
[2, 3, 4, 5], # 索引2的示例数据
[3, 4, 5, 6], # 索引3的示例数据
[4, 5, 6, 7], # 索引4的示例数据
]
calc_pull = 3 # 用实际的calc_pull值替换这里
y = range(calc_pull + 1)
ax = plt.subplot(111) # 设置一个子图
# 使用循环绘制不同蓝色的折线并添加标签
for i in range(1, len(ans_sum)):
x = ans_sum[i]
plt.plot(x, y, color=cm.Blues(0.8), lw=2.5, label=f'折线 {
i}')
# 为坐标轴和图表添加标签
plt.xlabel('X轴标签') # X轴标签
plt.ylabel('Y轴标签') # Y轴标签
plt.title('折线图示例') # 图表标题
# 打开坐标轴的次要刻度线
ax.minorticks_on()
# 在图表上添加网格线
plt.grid(True, which='major', alpha=0.6) # 主要网格线
plt.grid(True, which='minor', alpha=0.3) # 次要网格线
# 在图表上添加图例
plt.legend()
# 显示图表
plt.show()
【python】次要网格线(挖坑中)
猜你喜欢
转载自blog.csdn.net/qq_50653422/article/details/134792522
今日推荐
周排行