您可以使用 .plot 方法来绘制折线图,其中 x 轴为点的横坐标值,y 轴为点的纵坐标值。以下是使用 .plot 绘制散点为 (1,1)、(2,4)、(3,9)、(4,11) 的折线图的示例代码:

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y = [1, 4, 9, 11]

plt.plot(x, y)
plt.show()

运行这段代码后,会显示一个折线图,横坐标为 1、2、3、4,纵坐标为 1、4、9、11,并且通过这四个点绘制了一条折线连接起来。

Python Matplotlib 绘制折线图:示例代码与详解

原文地址: https://www.cveoy.top/t/topic/pkbb 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录