0

I am trying to recreate the results of the following Jupyter Notebook by copying the code and running it in PyCharm. When I run the code, I am not able to import numpy or matplotlib because they are showing up in grey, however, the other imports seem to work. I am trying to only recreate up until the 8th line in the Jupyter notebook but when I run that code I do not get any results and my code only finishes with "Process finished with exit code 0".

So I am wondering if copying and pasting from a Jupyter notebook might not be compatible with PyCharm or if someone might be able to provide insight as to why I cannot recreate the image then that would be helpful.

Here is a link to an image of the code I have, it is simply just a copy and paste from the Jupyter Notebook:

ForceBru
  • 43,482
  • 10
  • 63
  • 98
GrayLiterature
  • 381
  • 2
  • 13
  • 1
    "I am not able to import numpy or matplotlib because they are showing up in grey" - they're in grey because they aren't used in your code, and you can safely delete these imports. If you weren't able to import them, you'd get errors. – ForceBru Jul 08 '19 at 16:03
  • Do you have any insights as to why in the Jupyter notebook the graphs of line 8 won't appear in PyCharm? – GrayLiterature Jul 08 '19 at 16:06

1 Answers1

1

I think the code in the notebook works because it calls an iPython magic here:

import matplotlib.pyplot as plt
%matplotlib inline  # this is the iPython magic

So, as per this answer, this magic function will show the plots right away, while with a regular Python you'll have to call show:

import matplotlib.pyplot as plt

plt.plot(x, y)  # this line doesn't show anything, it only prepares the plot
plt.grid(True)  # modify the plot
plt.show()  # actually show the plot

Try calling plt.show() after results.plot().

ForceBru
  • 43,482
  • 10
  • 63
  • 98
  • The `plt.show()` function worked for me here. As someone new to Python, it's pretty challenging learning all the intricacies! So thank you. – GrayLiterature Jul 08 '19 at 16:11