在VS代码中使用DevContainer,如何显示Matplotlib图?

发布于 2025-01-19 12:30:34 字数 444 浏览 3 评论 0原文

我正在 VS Code 中运行 Ubuntu devcontainer。但是,当我运行创建绘图的 python 脚本时,即使使用 matplotlib.pyplot.show() ,绘图也不会显示在任何地方。我的猜测是 devcontainer 没有任何方式来显示它。我现在的解决方法是使用 matplotlib.pyplot.savefig() 保存绘图,但当我只想快速检查某些内容时,这不太好。

有谁知道如何查看 devcontainer 内创建的图?

这是我想做的一个例子:

import matplotlib.pyplot as plt
import numpy as np


# random data
x = np.linspace(0, 1, 100)
y = np.sin(np.pi * x)

# try plotting
plt.plot(x, y)
plt.show()

I'm running an Ubuntu devcontainer inside VS Code. However, when I run a python script that creates a plot, the plot doesn't show up anywhere, even when using matplotlib.pyplot.show(). My guess is that the devcontainer just doesn't have any way of displaying it. My workaround right now is to save the plot using matplotlib.pyplot.savefig(), but that's not great when I just want to check something quickly.

Does anyone know how to see the plots created inside the devcontainer?

Here's an example of what I'd like to do:

import matplotlib.pyplot as plt
import numpy as np


# random data
x = np.linspace(0, 1, 100)
y = np.sin(np.pi * x)

# try plotting
plt.plot(x, y)
plt.show()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文