显示多个水平对齐的图像,保持原始图像的大小



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

您可以使用带有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()

最新更新