我正在使用 matplotlib 绘制图表。当我使用以下代码在同一个图表中绘制它时:
def draw0(x, ys, labels):
plt.suptitle("big title")
i =0
for y in ys:
plt.plot(x, y, label=labels[i])
plt.scatter(x, y) # dots
plt.xticks(range(1, max(x) + 1))
plt.grid(True)
i+=1
plt.figlegend(loc="upper left")
plt.show()
return
x = [1,2,3,4,5]
y1 = [1,3,5,7,9]
y2 = [10,30,50,70,90]
y3 = [0.1,0.3,0.5,0.7,0.9]
draw0(x, [y1, y2, y3], ["chart1", "chart2", "chart3"])
Run Code Online (Sandbox Code Playgroud)
一切正常。 一个窗口中的图表 但我需要每个图表都位于单独的子图上。
我正在尝试这样做:
def draw11(x, ys, labels):
plt.figure()
plt.suptitle("big title")
i =0
for y in ys:
if i == 0:
ax = plt.subplot(len(ys),1, i+1)
else:
plt.subplot(len(ys), 1, i …Run Code Online (Sandbox Code Playgroud)