我试图将两个子图彼此相邻(而不是彼此相对).我期待看到[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()
Run Code Online (Sandbox Code Playgroud)
此致,
Axel
3个数字是行,列和图#.您正在做的是重新指定第二次调用子图中的列数,这反过来会更改配置并导致pyplot重新开始.
你的意思是:
subplot(121) # 1 row, 2 columns, Plot 1
...
subplot(122) # 1 row, 2 columns, Plot 2
Run Code Online (Sandbox Code Playgroud)
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()
Run Code Online (Sandbox Code Playgroud)