PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, May 14, 2022

[FIXED] How to use matplotlib backend "TkAgg" in Jupyter

 May 14, 2022     jupyter-notebook, matplotlib, python, ubuntu     No comments   

Issue

When running the following code in the Jupyter on Ubuntu 20.04:

import matplotlib
try:
    matplotlib.use("TkAgg")
    import matplotlib.pyplot as plt
except ImportError as e:
    print(e)
    plt = None

assert plt is not None, "matplotlib backend failed"
print("done")

Here is the output:

Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
/tmp/ipykernel_5612/97292621.py in <cell line: 9>()
      7     plt = None
      8 
----> 9 assert plt is not None, "matplotlib backend failed"
     10 print("done")

AssertionError: matplotlib backend failed

But I can run it directy from python3 command line without any problem.

Is there any python or system package need to be import or install first for running it in Jupyter notebook?


Solution

Try running this command on a empty cell:

%matplotlib tk

Then, execute your plotting commands.



Answered By - Davide_sd
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing