ShkarAhmad
ShkarAhmad

Reputation: 11

Pycharm Matplotlib backend doesn't change from Agg

Matplotlib resorts to Agg no matter what backend I give it.

Things I've tried:

  1. Changing the backend using matplotlib.use('Qt5Agg') and matplotlib.use('Qt5Agg', force=True)
import matplotlib
matplotlib.use('Qt5Agg', force=True)
import matplotlib.pyplot as plt
  1. Changing the backend in the matplotlibrc file
## ***************************************************************************
## * BACKENDS                                                                *
## ***************************************************************************
## The default backend.  If you omit this parameter, the first working
## backend from the following list is used:
##     MacOSX Qt5Agg Gtk3Agg TkAgg WxAgg Agg
## Other choices include:
##     Qt5Cairo GTK3Cairo TkCairo WxCairo Cairo
##     Qt4Agg Qt4Cairo Wx  # deprecated.
##     PS PDF SVG Template
## You can also deploy your own backend outside of matplotlib by referring to
## the module name (which must be in the PYTHONPATH) as 'module://my_backend'.
#backend: Qt5Agg

Printing the backend gives the following:

print(matplotlib.get_backend())
print(matplotlib.is_interactive())

Qt5Agg
False

Yet when I try to use plt.show() the following error occurs:

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

I don't know wether this is a Pycharm or Matplotlib error. Hope you guys have any ideas

Shkar

Upvotes: 1

Views: 1158

Answers (1)

Alles Klar
Alles Klar

Reputation: 21

In my case (Linux Mint 20.3) the issue came from installing PyCharm from the Software Manager. PyCharm then was installed with flatpak

flatpak list

should give show you an idea if it is so too.

There are issues with that version. Have a look at: https://github.com/flathub/com.jetbrains.PyCharm-Community/issues/15

I could fix it by installing PyCharm with snapd. https://thesecmaster.com/3-ways-to-install-pycharm-on-linux-mint-and-ubuntu/

then: sudo apt-get install python3.8-tk and within PyCharm I had to add

"future" and "matplotlib"

More information about it: When you run PyCharm the first time (installed from Software Manager) you receive:

https://www.flathub.org


| Warning: You are running an unofficial Flatpak version of PyCharm !!! |

Please open issues under: https://github.com/flathub/com.jetbrains.PyCharm-Community/issues

This version is running inside a container and is therefore not able to access SDKs on your host system!

Upvotes: 1

Related Questions