Python Matplotlib 折线图制作教程:简单易懂的代码示例
以下是 Python 中使用 matplotlib 库制作折线图的基本代码:
import matplotlib.pyplot as plt
# 准备数据
x = [1, 2, 3, 4, 5]
y = [10, 8, 6, 4, 2]
# 绘制折线图
plt.plot(x, y)
# 添加标题和坐标轴标签
plt.title('Line Chart')
plt.xlabel('X Label')
plt.ylabel('Y Label')
# 显示图形
plt.show()
在这个例子中,我们使用了两个列表作为折线图的数据,分别是 x 和 y。我们使用 plot 函数绘制折线图,然后使用 title、xlabel 和 ylabel 函数添加标题和坐标轴标签。最后,我们使用 show 函数显示图形。
你可以根据需要自行修改数据和标签,以及添加更多的设置来自定义折线图。
原文地址: http://www.cveoy.top/t/topic/nZuy 著作权归作者所有。请勿转载和采集!