尝试将子图相邻放置

5

我试图将两个子图并排展示(而不是垂直堆叠)。我期望看到[sp1] [sp2]
但实际上只有第二个图[sp2]被展示。

from matplotlib import pyplot

x = [0, 1, 2]

pyplot.figure()

# sp1
pyplot.subplot(211)
pyplot.bar(x, x)

# sp2
pyplot.subplot(221)
pyplot.plot(x, x)

pyplot.show()
2个回答

12

这三个数字指的是行数、列数和图表编号。你在第二次调用subplot时重新指定了列数,这改变了配置并导致pyplot重新开始。

你想表达的意思是:

subplot(121)  # 1 row, 2 columns, Plot 1
...
subplot(122)  # 1 row, 2 columns, Plot 2

这将会把它们显示在彼此下方,而不是旁边。 - Axel
2
我刚刚意识到你可能是指: subplot(121) subplot(122) 感谢您的回复。 - Axel

5
from matplotlib import pyplot

x = [0, 1, 2]

pyplot.figure()

# sp1
pyplot.subplot(121)
pyplot.bar(x, x)

# sp2
pyplot.subplot(122)
pyplot.plot(x, x)

pyplot.show()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接