python matplotlib绘制多条折线图
代码
import matplotlib.pyplot as plt
x = [6, 24, 48, 72]
y1 = [87, 174, 225, 254]
y2 = [24, 97, 202, 225]
y3 = [110, 138, 177, 205]
y4 = [95, 68, 83, 105]
y5 = [72, 74, 76, 67]
plt.title('扩散速度')
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.xlabel('时间')
plt.ylabel('差值')
plt.plot(x, y1, marker='o', markersize=3)
plt.plot(x, y2, marker='o', markersize=3)
plt.plot(x, y3, marker='o', markersize=3)
plt.plot(x, y4, marker='o', markersize=3)
plt.plot(x, y5, marker='o', markersize=3)
for a, b in zip(x, y1):
plt.text(a, b, b, ha='center', va='bottom', fontsize=10)
for a, b in zip(x, y2):
plt.text(a, b, b, ha='center', va='bottom', fontsize=10)
for a, b in zip(x, y3):
plt.text(a, b, b, ha='center', va='bottom', fontsize=10)
for a, b in zip(x, y4):
plt.text(a, b, b, ha='center', va='bottom', fontsize=10)
for a, b in zip(x, y5):
plt.text(a, b, b, ha='center', va='bottom', fontsize=10)
plt.legend(['方案一', '方案二', '方案三', '方案四', '方案五'])
plt.show()
折线图
