Increase DPI of Matplotlib .show() in Jupyter Notebook

If your screen has Retina display, add the following line after %matplotlib inline (or somewhere else before plotting) in your notebook

%config InlineBackend.figure_format = 'retina'

This will increase the display resolution of your plots within the Jupyter Notebook.


Add this at the beginning of the notebook:

import matplotlib as mpl
mpl.rcParams['figure.dpi'] = 300

That's it !


Using the solution proposed in this answer has the drawbacks to apply the DPI to all the other figures that will be created within the notebook.

This is fine in most cases, but if you need to set the DPI value ONLY for one figure, you can do it as follows:

plt.imshow(img)
plt.gcf().set_dpi(300)
plt.show()