Python 和 R : how do you show a plot with Pyper in a Jupyter notebook?

标签 python r jupyter rpy2 pyper

我正在使用 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/

相关文章:

r - 基于日期比较的子集数据集R

python - 如何将这个嵌套的 for 循环写成列表理解?

python - 使用 Python3 将 meld 设置为 git mergetool

python - 朴素高斯预测概率只返回 0 或 1

r - 如何使用 foreach 和 doMC 包为随机模拟设置种子?

删除单个 dplyr group_by 组

python-2.7 - 如何使用 python 2.x 安装 jupyter/docker-stacks

python - Mac 上的 Jupyter : run files from non-default directory

python - 将数组范围作为参数传递给函数?

python - 如何使已打开的文件可读(例如 sys.stdout)?