Emacs 中可以有交互式绘图吗?

问题描述 投票:0回答:1

我尝试使用 Emacs 作为我的研究编辑器(我遵循 Jon Fincher 的 Realpython 指南中的所有步骤:[https://realpython.com/emacs-the-best-python-editor/])。

我经常使用 jupyter 笔记本进行数据可视化,因此我安装了 ein [https://github.com/millejoh/emacs-ipython-notebook]。 我可以在 Emacs (pyvenv-workon) 中使用我的虚拟环境,打开我的笔记本,运行所有单元格:直到我启动一个带有 maptlotlib 图的单元格。

在 jupyter 中为了获得交互式绘图,我将“%matplotlib nbagg”放入我的代码单元格中,它工作得很好。 在 Emacs 中它打印 «

在理想的世界中,我还希望能够看到 matplotlib 动画。

我浏览了一下,我想我明白 Emacs 无法使用 Javascript 对象,这是正确的吗?对我来说,一个可能的解决方法是将interactive图放在单独的窗口中,但我没有找到如何做到这一点,是否有一些我错过的wiki?

干杯

· %matplotlib nbagg 在jupyter笔记本浏览器界面中返回一个交互式图形,似乎在Emacs中不起作用。

· plt.ion() 应该提供交互式访问,但不执行任何操作。

· %matplotlb inline 打开带有绘图的非交互式 .png 文件

matplotlib jupyter-notebook emacs interactive matplotlib-animation
1个回答
0
投票

可能有点晚了,但是,其他有类似问题的人仍然可以利用这个。

要使用 Emacs(用于 python 主要模式的 elpy 包)显示交互式 matplotlib 绘图,有两种有效方法(据我测试):

1. 在调用绘图函数之前,可以将 Qt 设置为后端,

matplotlib.use("qtAgg")

确保 elpy 使用的 python 环境中通过

pip install pyqt5
安装了 pyqt5。

检查过:

  • 2023 年 7 月 31 日的 GNU Emacs 29.1(版本 2,x86_64-w64-mingw32)
  • 埃尔皮1.35.0
  • Jupyter 控制台 6.6.3(elpy-config 中的 python-shell-interpreter 变量设置为 jupyter)
  • Python 3.11.4
  • Matplotlib 3.8.3
  • Pyqt5:PyQt5-Qt5-5.15.2、PyQt5-sip-12.13.0、pyqt5-5.15.10

2. 使用

webAgg
作为 matplotlib 的后端。这不需要其他软件包,但每次都会打开浏览器选项卡/窗口。

MWE:

import matplotlib
import matplotlib.pyplot as plt
import numpy as np

matplotlib.use("qtAgg")

plt.plot(np.random.normal(0,1,(10, 1)))
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.