我正在使用 Jupyter 创建报告。我的大部分代码都是用 Python 编写的,但我需要使用一些 R 功能。
我使用一个名为 Pyper 的包在 Python 中调用 R。它运行良好,但我无法弄清楚如何在 Jupiter 笔记本中显示用 R(通过 Pyper)制作的图。一切似乎都运行良好,但 Jupyter 不显示情节。
这是我的测试代码:
In [17]: from pyper import *
r = R()
r("library(TSA)")
r("data(star)")
r("periodogram(star)")
这是 Jupyter 的输出(没有周期图):
Out[17]: 'try({periodogram(star)})\n'
最佳答案
如果有人在使用 Pyper 并想向 Jupyter 添加绘图,我已经找到了解决方法:
from pyper import *
r = R()
r("library(TSA)")
r("data(star)")
# Save the figure
r("png('rplot.png');periodogram(star);dev.off()")
# Upload the figure to Jupyter
from IPython.display import Image
Image("rplot.png",width=600,height=400)
关于Python 和 R : how do you show a plot with Pyper in a Jupyter notebook?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38667572/