如何使用 matplotlib 繪制水平對齊的多個影像并保持原始影像大小?
uj5u.com熱心網友回復:
您可以使用帶有 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()
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/357822.html
標籤:Python 图片 matplotlib
上一篇:Mnist隨機樣本繪圖不起作用?
下一篇:如何使用plt繪制拋物線和點?
