【问题标题】:Display multiple images horizontally aligned keeping original images sizes显示多个水平对齐的图像,保持原始图像大小
【发布时间】:2021-11-15 14:28:22
【问题描述】:

如何使用 matplotlib 绘制多个水平对齐的图像以保持原始图像大小?

【问题讨论】:

    标签: python image matplotlib


    【解决方案1】:

    您可以使用带有 matplotlib 的子图来构建一个网格,每个案例将显示一个图像。您可以使用 figsize 来调整网格的整体大小以达到您的原始图像大小。

    import matplotlib.pyplot as plt
    import numpy as  np
    # creating some data for the plots (from matplotlib simple plots)
    t = np.arange(0.0, 2.0, 0.01)
    s = 1 + np.sin(2 * np.pi * t)
    # creating the grid
    num_rows = 4
    num_cols = 2
    num_images = num_rows*num_cols
    plt.figure(figsize=(2*2*num_cols, 2*num_rows)) # here you can adapt the size of the figure
    for i in range(num_images):
        plt.subplot(num_rows, num_cols, i+1) # adding a subplot
        plt.plot(t, s) # adding a plot to the subplot
    plt.tight_layout()
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2013-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-06
      • 2010-11-28
      • 1970-01-01
      • 1970-01-01
      • 2017-09-01
      相关资源
      最近更新 更多