做折线图的代码
以下是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函数显示图形。
你可以根据需要自行修改数据和标签,以及添加更多的设置来自定义折线图。
原文地址: https://www.cveoy.top/t/topic/eQAU 著作权归作者所有。请勿转载和采集!