matplotlib.axes.axes.plot
matplotlib.axes.axes.plot()函数,matplotlib库的Axes模块中的Axes.plot()函数用于将y和x绘制为直线和/或标记。
语法:
axes.plot(self, *args, scalex=True, scaley=True, data=None, **kwargs)
参数:该方法接受如下参数说明:
- x, y:这些参数是数据点的水平和垂直坐标。X为可选值。
- fmt:可选参数,包含字符串值。
- data:可选参数,是带标签数据的对象。
返回如下内容:
- lines:返回表示绘制数据的Line2D对象列表。
下面的例子演示了matplotlib.axes.axes.plot()函数在matplotlib.axes中的作用:
示例1
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
# make an agg figure
fig, ax = plt.subplots()
ax.plot([1, 2, 3])
ax.set_title('matplotlib.axes.Axes.plot() example 1')
fig.canvas.draw()
plt.show()
输出:
示例2
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
# Fixing random state for reproducibility
np.random.seed(19680801)
# create random data
xdata = np.random.random([2, 10])
# split the data into two parts
xdata1 = xdata[0, :]
xdata2 = xdata[1, :]
# sort the data so it makes clean curves
xdata1.sort()
xdata2.sort()
# create some y data points
ydata1 = xdata1 ** 2
ydata2 = 1 - xdata2 ** 3
# plot the data
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(xdata1, ydata1, color ='tab:blue')
ax.plot(xdata2, ydata2, color ='tab:orange')
# set the limits
ax.set_xlim([0, 1])
ax.set_ylim([0, 1])
ax.set_title('matplotlib.axes.Axes.plot() example 2')
# display the plot
plt.show()
输出: