Python 折线图绘制教程:Matplotlib 库入门
要使用 Python 绘制折线图,需要使用 Matplotlib 库。下面是一个简单的例子:
import matplotlib.pyplot as plt
# 定义数据
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
# 绘制折线图
plt.plot(x, y)
# 添加标题和标签
plt.title('My Line Chart')
plt.xlabel('X Axis Label')
plt.ylabel('Y Axis Label')
# 显示图形
plt.show()
这将绘制一个简单的折线图,其中 x 轴上的标签为 1 到 5,y 轴上的标签为 2 到 10。您可以使用其他函数来自定义图形,例如添加颜色,样式等。
原文地址: https://www.cveoy.top/t/topic/mRz6 著作权归作者所有。请勿转载和采集!