前言
- ? 运行环境:python3
- ? 作者:K同学啊
- ? 精选专栏:《深度学习100例》
- ? 推荐专栏:《新手入门深度学习》
- ? 选自专栏:《Matplotlib教程》
- ? 优秀专栏:《Python入门100题》
代码实现
import numpy as np
import matplotlib.pyplot as plty1 = [2.3, 3.6, 3.4, 4.6, 5.9, 6.6, 6.9]
y2 = [2 , 2.8, 2.1, 4.1, 4.5, 5.9, 6]
x = ["a","b","c","d","e","f","g"]
""" 绘制折线图方法plot 参数一:y轴 参数二:x轴 """
plt.figure(figsize=(8,5))
plt.plot(x, y1, label="line L", color='lime', alpha=0.8, linewidth=2, linestyle="--")
plt.plot(x, y2, label="line H", color='gold', alpha=0.8, linewidth=2, linestyle="-")plt.ylim(0,9)plt.xlabel("x axis", fontsize=12)
plt.ylabel("y axis", fontsize=12)
plt.title("Line Graph Example", fontsize=14)for x, y1 in enumerate(y1):plt.text(x, y1, y1)for x, y2 in enumerate(y2):plt.text(x, y2, y2)plt.legend()
plt.show()