Issue
How can I plot multiple images horizontally aligned keeping original images sizes with matplotlib?
Solution
You can use subplots with matplotlib to build a grid which will display one image per case. You can use figsize to adapt the overall size of the grid to get to your original image size.
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()
Answered By - Jacques
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.