为什么这个 Jupyter 代码不能 运行 in Python?

Why can't this Jupyter Code run in Python?

我正在尝试通过复制代码并运行在PyCharm中重新创建以下Jupyter Notebook的结果。当我 运行 代码时,我无法导入 numpy 或 matplotlib,因为它们显示为灰色,但是,其他导入似乎有效。我试图只重新创建直到 Jupyter 笔记本中的第 8 行,但是当我 运行 该代码时,我没有得到任何结果,我的代码只以 "Process finished with exit code 0" 结束。

所以我想知道从 Jupyter notebook 复制和粘贴是否可能与 PyCharm 不兼容,或者如果有人能够提供有关我无法重新创建图像的原因的见解,那将会有所帮助。

这是我拥有的代码图像的 link,它只是从 Jupyter Notebook 中复制和粘贴:

我认为笔记本中的代码有效,因为它在这里调用了 iPython 魔法:

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

因此,根据 this answer,这个神奇函数将立即 显示 绘图,而对于常规 Python,您必须调用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

尝试在 results.plot() 之后调用 plt.show()