Displaying images at full size in Jupyter

Viewed 2403

I try to display images inside a Jupyter notebook. To do that, I use a code like the following one:

import numpy as np
import matplotlib.pyplot as plt
for N in [20, 100, 300]:
  x, y = np.meshgrid(np.linspace(1,N,N), np.linspace(1,N,N))
  img = (x+y) % 2
  plt.figure()
  plt.imshow(img,cmap='gray')
  plt.title("Image shape: " + str(img.shape));

I obtain the images below:

big squares meddium squares small squares

As you can see, the images are not properly displayed because they are resized so as to have the same size on the screen. Therefore, the images are interpolated (to the nearest neighbors), creating unwanted aliasing. This is too bad for image processing...

I tried to define figsize and dpi in figure, but that not works.

1 Answers

I used this & it worked:

import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (width,height)

(Here width & height are in inches)

For more detail, you can have a look at this question

Related