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
x
8
1
NameError Traceback (most recent call last)
2
< ipython-input-1-1eb00ff78cf2> in <module>
3
4
----> 1 plt.show()
5
6
7
NameError: name 'plt' is not defined
8
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
1
10
10
1
%matplotlib ipympl
2
3
import matplotlib.pyplot as plt
4
5
a_x=[1,2,3,4,5,6]
6
a_y=[1,2,3,4,5,6]
7
8
plt.plot(a_x, a_y)
9
plt.show()
10
A video of the problem is available here.
- Selected
Run
- Resulting error
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 only executed the selected line (9) with
- You can see the problem by carefully reading the traceback.
Line 9
in the script isline 1
in the traceback:----> 1 plt.show()
- The solution is to run the whole file, not one line. Click Run All not Run.