0

I have installed matplotlib but still when I run the program it shows:

Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. plt.show()

How to resolve this issue?

Zanna
  • 69,223
  • 56
  • 216
  • 327
  • 1
    [How can I set the 'backend' in matplotlib in Python?](https://stackoverflow.com/questions/4930524/how-can-i-set-the-backend-in-matplotlib-in-python) – steeldriver Sep 09 '20 at 14:16

1 Answers1

1

The following code works in PyCharm. Pillow is packaged as python3-pil and matplotlib is packaged as python3-matplotlib in Ubuntu. The image is displayed in a new window. I copied my image, named image.png, into my PyCharm project's venv folder so that PyCharm would find it automatically.

import matplotlib.pyplot as plt
from PIL import Image

fname = 'image.png'
plt.imshow(Image.open(fname))
plt.show()

Note: PyCharm does not automatically find your globally installed Python packages unless the project has been configured to find them. To do this select the Inherit global-site packages option when you create a new project.

Select FileNew Project to create a new project. Click the triangle marked by the mouse cursor in the below screenshot to show the new project's options.

Create Project window

Then check the Inherit global-site packages checkbox and click the Create button in the lower right corner of the Create Project window.

enter image description here

BeastOfCaerbannog
  • 12,964
  • 10
  • 49
  • 77
karel
  • 110,292
  • 102
  • 269
  • 299