Import Issue with Matplotlib and Pyplot (Python / Tkinter)

Adam Davis

I am having an issue where I cannot call the 'pyplot' element of 'matplotlib'. From the code below you can see I've had to add a "TkAgg" for the mattplotlib element to work, which is a common issue.

import matplotlib
matplotlib.use("TkAgg")

However, now I cannot add the '.pyplot' to the import. I've tried the following:

import matplotlib.pyplot as plt
plt.use("TkAgg")

But this gives me the error:

AttributeError: module 'matplotlib.pyplot' has no attribute 'use'

How can I get around this as my code requires pyplot to function, but I cannot work out how to import it while still having to use ".use("TkAgg").

I am running Python 3.6.2 and I am using Tkinter to develop my program

ImportanceOfBeingErnest

Those are two entirely different things. You import matplotlib to be able to set the backend. Then you need to still import pyplot to be able to use it afterwards.

import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
# ... rest of code

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

tkinter error when trying to import matplotlib.pyplot in Arch Linux

From Dev

Embedded python crashes upon import of matplotlib.pyplot

From Dev

Embedded python crashes upon import of matplotlib.pyplot

From Dev

Is "from matplotlib import pyplot as plt" == "import matplotlib.pyplot as plt"?

From Java

Unable to "import matplotlib.pyplot as plt" in virtualenv

From Dev

Failure to import matplotlib.pyplot in jupyter (but not ipython)

From Dev

Tkinter window does not close if used with matplotlib.pyplot

From Dev

Python Tkinter scrollbar issue

From Dev

Python Tkinter Checkbutton Issue

From Dev

Python - Tkinter CheckButton Issue

From Dev

Can't import matplotlib.pyplot, IOError related to a font

From Dev

When trying to import Matplotlib.pyplot, get "UnicodeDecodeError"

From Dev

Python - matplotlib.pyplot ion() slow

From Dev

How to set xlim in python matplotlib pyplot?

From Dev

How to set xlim in python matplotlib pyplot?

From Dev

Python tornado import issue

From Dev

Python advanced import issue

From Dev

Python import/from issue

From Dev

python class import issue

From Dev

Python import modules issue

From Java

Installation Issue with matplotlib Python

From Dev

Python tkinter 8.5 import messagebox

From Dev

python import ttk and * from tkinter

From Dev

Psychopy can import matplotlib but can't import pyplot though it's on my Mac

From Dev

Tkinter grid() alignment issue in python

From Dev

Import issue with Python six library

From Dev

Python module import issue subdir

From Dev

matplotlib installation issue python 3

From Dev

In iPython, keep the Python Shell available after matplotlib.pyplot.show()

Related Related

HotTag

Archive