I'm trying to write a code for a function that displays the first 20 misclassified images in the form of the output below.
Try 1
use subplots_adjust
#Try 1
DISPLAY_CNT = 20
FIG_ROW_CNT = 2
_FIG_COL_CNT = int(DISPLAY_CNT / FIG_ROW_CNT)
_TOTAL_DISPLAY_CNT = FIG_ROW_CNT * _FIG_COL_CNT
def display_first_20(list):
j = 1
fig = plt.figure(figsize=(15, 15))
for i in range(_TOTAL_DISPLAY_CNT):
plt.subplot(FIG_ROW_CNT, _FIG_COL_CNT, j)
img = x_train[i]
img = img.reshape(28, 28)
plt.imshow(img)
plt.title("{}/{}".format(classify(i), d_test[i]))
plt.axis('off')
j += 1
plt.subplots_adjust(left=0.1, right=0.9, bottom=0.1, top=0.9,
hspace=0.1, wspace=0.1)
plt.show()
fail_list = failed_list()
display_first_20(fail_list[:DISPLAY_CNT])
but there's big white blank between rows. and I also tried changing hspace & wspace,still doesn't work.
so I changed subplots_adjust to fig.tight_layout()
Try 2
use fig.tight_layout()
DISPLAY_CNT = 20
FIG_ROW_CNT = 2
_FIG_COL_CNT = int(DISPLAY_CNT / FIG_ROW_CNT)
def display_first_20(list):
j = 1
fig = plt.figure(figsize=(20, 10))
for i in list:
plt.subplot(FIG_ROW_CNT, _FIG_COL_CNT, j)
img = x_train[i]
img = img.reshape(28, 28)
plt.imshow(img)
plt.title("{}/{}".format(classify(i), d_test[i]))
plt.axis('off')
j += 1
fig.tight_layout()
plt.show()
fail_list = failed_list()
display_first_20(fail_list[:DISPLAY_CNT])
reduced some but still big to compare with first pic.
How can I make the code to display like first pic?