jub
jub

Reputation: 417

matplotlib using non-GUI backend even though tkinter is installed and imported

I'm using the Jupyter notebook extension in VS Code. I'm using Camelot to extract tables from a pdf, and I'm trying to do some visual debugging to find the coordinates of the column separators.

When running:

camelot.plot(tables[1], kind='text').show()

I get the warning: "UserWarning: Matplotlib is currently using module://matplotlib_inline.backend_inline, which is a non-GUI backend, so cannot show the figure."

From https://pythonguides.com/matplotlib-is-currently-using-agg-a-non-gui-backend/ I understood the problem is I have no GUI backend. That website suggests using tkinter as the GUI backend. So I did pip install tk to install tkinter into my virtual environment. Then added import to my code: from tkinter import *.

After closing the project folder, exiting VS Code and restarting, when I run

camelot.plot(tables[1], kind='text').show()

I get the same warning: "UserWarning: Matplotlib is currently using module://matplotlib_inline.backend_inline, which is a non-GUI backend, so cannot show the figure."

How do I get a GUI backend set up the way matplotlib wants?

Upvotes: 0

Views: 720

Answers (1)

jub
jub

Reputation: 417

Seems there are various solutions, some of which are dated. A solution I found that works as of this post (2022) is

  1. install ipympl to the environment (since I already have jupyter notebook installed in my virtual env, all of the requirements for ipympl were already present, and the only package that needed to be installed was 'ipympl' itself.
  2. add the following code (after import statements): %matplotlib widget

That's it. Now I when I plot something, I get the usual static plot as well as an interactive plot that allows me to see x,y coordinates on the plot as I move the mouse around.

Upvotes: 1

Related Questions