Ipython, "Name 'Plt' Not Defined"

I recently installed Atom as an IDE on my laptop, for university. I installed Hydrogen as a convenient solution to show some plots on the go. But whenever I run Hydrogen, I get this error:

NameError                                 Traceback (most recent call last)
< ipython-input-1-1eb00ff78cf2>  in <module>

----> 1 plt.show()


NameError: name 'plt' is not defined

However Matplotlib is working properly when executed normally, and IPython seems to do as well. This is the code I'm trying to run test-wise:

%matplotlib ipympl

import matplotlib.pyplot as plt

a_x=[1,2,3,4,5,6]
a_y=[1,2,3,4,5,6]

plt.plot(a_x, a_y)
plt.show()

A video of the problem is available here.

  • Selected Run
  • Resulting error
0

You have to import the library first. Add this at start of the code.-

from matplotlib import pyplot as plt
1
  • You ran one line, not the whole file.
  • You can see the problem by carefully reading the traceback. Line 9 in the script is line 1 in the traceback: ----> 1 plt.show()
  • The solution is to run the whole file not one line, i.e. click Run All not Run.
0
Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest