I am trying to save plots from pyplot as .png using the following code:
import numpy as np
import os
from matplotlib import pyplot as pl
os.chdir("/WORKING/DIRECTORY")
array1 = np.random.rand(10, 3)
array2 = np.random.rand(50, 3)
array3 = np.random.rand(400, 3)
arrays = (array1, array2, array3)
dpi = 300
count = 1
for n in arrays:
pl.imshow(n, cmap='Accent')
pl.axis('off')
pl.savefig(str(count) + ".png", bbox_inches='tight', pad_inches=0, dpi=dpi)
count +=1
Depending on the array size the results are not as expected. Array1 renders fine. Array2 renders ok, but the last column of values is cut off (a few pixel less wide than the first two columns). Array3 is completely distorted.
Increasing the resolution fixes the problem. I don't want to do that globally as most of my files don't require it. How can I detect the files that are rendered wrong? Pyplot does not return an error eg for array2 or array3. Attached image files for reference.
Any idea how to pick this up as an error or bin the files into a separate folder? Array 1, Array 2, Array3