You could add it directly after output = model(data).
The better approach would probably be to store all predictions in a list and plot some images after the test loop finshes:
preds = []
for data, target in test_loader:
    ...
    output = model(data)
    pred = torch.argmax(output.detach(), 1)
    preds.append(pred)
    ...

nb_imgs_to_plot = 4
fig, axarr = plt.subplots(4)
for idx, img in enumerate(preds[:nb_imgs_to_plot]):
    axarr[idx].imshow(img.numpy())