1

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

1
  • For those running in to this problem aswell. A very dirty fix is to add everytime plt.switch_backend('Qt5Agg') before showing the plot. Commented Jan 30, 2021 at 21:31

1 Answer 1

1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.