我正在使用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)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句