如何在 Visual Studio Code 本身中显示图形?
当我尝试运行此示例时:
When I try to run this example:
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
x = np.linspace(0, 20, 100)
plt.plot(x, np.sin(x))
plt.show()
我在新窗口中看到了结果.是否可以在Visual Studio Code本身中查看结果图?
I see the result in a new window. Is it any way to see the result graphs in the Visual Studio Code itself?
是的,如果您使用笔记本界面.基本上,安装 Python 扩展包,它包含 Jupyter 扩展,将您的代码放入编辑器中,将 #%%
放在代码顶部,您将获得 Run cell
单击,单击它,您将在另一个窗口中获得结果
Yes, if you use notebook interface. Basically, install Python Extension Pack, it includes Jupyter extension, put your code in the editor, put #%%
at the top of your code, you'll get Run cell
clickable, click it, and you'll get result in the other window
以下是扩展名的链接: https://marketplace.visualstudio.com/items?itemName=donjayamanne.jupyter
更新
好的,显然微软聘请了 Don Jayamanne,他正在为 VS Code 开发 Python 和 Jupyter.上个月,他们 (MS) 改进了他们的 python 扩展,以支持 Visual Code 中的 Jupyter notebooks 以及 .ipynb 导入和导出.获取扩展此处并检查
Ok, apparently Microsoft hired Don Jayamanne and he's working on Python and Jupyter for VS Code. And last month they (MS) improved their python extension to support Jupyter notebooks right in the Visual Code together with .ipynb import and export. Get extension here and check blog post how to use it with Jupyter notebooks.
更新二
另一个是神经元,正在开发中,但看起来不错 - 同样是 VS Code 中的笔记本,带有图表、降价等.获取它这里
Another one is Neuron, under development, but looks nice - again, notebooks in VS Code, with graphs, markdown etc. Get it here