jupyter notebook won't show images

Viewed 2011
#%%

from Utils.ConfigProvider import ConfigProvider
import os
import cv2
import numpy as np
from matplotlib import pyplot as plt
config = ConfigProvider.config()

and

#%%

inspected = cv2.imread(config.data.inspected_image_path, 0)
reference = cv2.imread(config.data.reference_image_path, 0)
diff = np.abs(inspected - reference)

plt.figure()
plt.title('inspected')
plt.imshow(inspected)

plt.show()

note config.data.inspected_image_path and config.data.reference_image_path are valid paths.


No errors appear, but no images are shown as well.

Running the same code from a python file does show the image.

I have something missing from the notebook.

This happens both when running using jupyter notebook and directly from PyCharm (pro)

How do I get to see images? all other answers I found just tell me to plt.show() but this obviously does not work.

I don't mind a cv2 solution as well.

1 Answers

You need to set a matplotlib backend.

You can do this with

%matplotlib inline

If you want to be able to interact with the plot, use

%matplotlib notebook
Related