【问题标题】:Trying to position subplots next to each other尝试将子图彼此相邻放置
【发布时间】:2010-12-09 15:23:06
【问题描述】:

我正在尝试将两个子图彼此相邻放置(而不是在彼此下方)。我期待看到 [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()

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

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

    你的意思是:

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

    【讨论】:

    • 这会将它们显示在彼此下方,而不是相邻。
    • 我才意识到您的意思可能是:subplot(121) subplot(122) 感谢您的回复
    【解决方案2】:
    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()
    

    【讨论】:

      猜你喜欢
      • 2015-10-29
      • 1970-01-01
      • 2022-01-20
      • 2020-07-22
      • 2017-05-08
      • 2015-07-27
      • 1970-01-01
      • 1970-01-01
      • 2013-04-22
      相关资源
      最近更新 更多