我正在使用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'发布于 2016-07-30 05:50:23
我已经找到了一个解决方法,如果有人正在使用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)https://stackoverflow.com/questions/38667572
复制相似问题