Skip to content
Advertisement

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:

JavaScript

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:

JavaScript

A video of the problem is available here.

enter image description here

  • Selected Run

enter image description here

  • Resulting error

enter image description here

Advertisement

Answer

  • As shown in the OP, import matplotlib.pyplot as plt is present, but it didn’t get executed.
    • You only executed the selected line (9) with plt.show(), 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. Click Run All not Run.
Advertisement