Python plt.plot: How to Use Matplotlib Plot

The plt.plot() function is used in the matplotlib library to draw line plots. It is typically used to connect a series of data points with a continuous line. The basic usage of the plt.plot() function is as follows:

import matplotlib.pyplot as plt

# 创建数据
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]

# 绘制折线图
plt.plot(x, y)

# 显示图形
plt.show()

In the example above, we first import the matplotlib library, then create two lists x and y to store the data for the x and y coordinates. We then use the plt.plot() function to plot the line graph, and finally call the plt.show() function to display the graph. The plt.plot() function also supports setting various properties such as line color, line style, markers, as well as adding legends, axis labels, and more.

bannerAds