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()
4

2 回答 2

12

这 3 个数字是行、列和绘图 #。您正在做的是在第二次调用 subplot 时重新指定列数,这反过来会更改配置并导致 pyplot 重新开始。

你的意思是:

subplot(121)  # 1 row, 2 columns, Plot 1
...
subplot(122)  # 1 row, 2 columns, Plot 2
于 2009-10-23T23:38:28.843 回答
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()
于 2009-10-23T23:53:05.890 回答