The easiest way IMHO is actually using package Pillow to export the data. The minimum example would be,
import numpy as np
from PIL import Image
i = np.full((100, 100, 3), 0.5, dtype=np.double)
im = Image.fromarray(i, mode='RGB')
im.save("img.png")
In the case of using matplotlib, you may want to try this method, subplots_adjust
. Example:
import numpy as np
import matplotlib.pyplot as plt
my_dpi=100
i = np.full((100, 100, 3), 0.5, dtype=np.double)
fig, ax = plt.subplots(
figsize=(100/my_dpi,100/my_dpi),
facecolor='red', dpi=my_dpi
)
ax.imshow(i)
ax.axis('off')
plt.subplots_adjust(0, 0, 1, 1)
plt.show()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…