方法1plt.plot(x, y)
这样,您只需绘制一个具有(x,y)坐标的图形。如果你只想得到一个图形,你可以用这种方式。
方法2ax = plt.subplot()
ax.plot(x, y)
这样可以在同一窗口中绘制一个或多个图形。当你写的时候,你只会画出一个图形,但是你可以这样做:fig1, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
您将在同一窗口中绘制4个图形,分别命名为ax1、ax2、ax3和ax4。这个窗口将用我的例子分成4部分。
方法3fig = plt.figure()
new_plot = fig.add_subplot(111)
new_plot.plot(x, y)
我没用,但你可以找到文件。
示例:import numpy as np
import matplotlib.pyplot as plt
# Method 1 #
x = np.random.rand(10)
y = np.random.rand(10)
figure1 = plt.plot(x,y)
# Method 2 #
x1 = np.random.rand(10)
x2 = np.random.rand(10)
x3 = np.random.rand(10)
x4 = np.random.rand(10)
y1 = np.random.rand(10)
y2 = np.random.rand(10)
y3 = np.random.rand(10)
y4 = np.random.rand(10)
figure2, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
ax1.plot(x1,y1)
ax2.plot(x2,y2)
ax3.plot(x3,y3)
ax4.plot(x4,y4)
plt.show()
其他示例: