pip install matplotlib
]]>
import matplotlib.pyplot as plt
# 创建数据
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
# 绘制折线图
plt.plot(x, y)
plt.title('简单折线图')
plt.xlabel('X轴')
plt.ylabel('Y轴')
plt.show()
]]>
plt.plot(x, y, color='red', marker='o')
plt.title('带标记的折线图')
plt.xlabel('X轴')
plt.ylabel('Y轴')
plt.show()
]]>
z = [1, 4, 9, 16, 25]
plt.plot(x, y, label='数据1', color='blue', marker='o')
plt.plot(x, z, label='数据2', color='green', marker='s')
plt.title('多条折线图')
plt.xlabel('X轴')
plt.ylabel('Y轴')
plt.legend()
plt.show()
]]>