2017-09-22 9 views
2

私はJupyterノートブックでpython 3xを使用していますが、私がしたいのは、Rupプロットのいくつかをjupyterノートブックのシェルにプロットすることです。しかし、私がそうすると、プロットはシェルではなく別のウィンドウに描画されるという問題があります。しかし、私はそれを閉じたときにjupyterノートは私にエラーを与える「デッドカーネル」なぜPythonが応答しないのですか?ウィンドウはプログラムを復元しようとする可能性があります。プログラムを復元または終了すると、情報が失われる可能性があります。

enter image description here

は私のコードは次のとおりです。私はこの

を取得していたプログラムを閉じ

# To fit a restricted VAR model we will have to call the function from R 

# Call function from R 
from rpy2.robjects.packages import importr 
from rpy2.robjects import pandas2ri 
pandas2ri.activate() 

# Calling packages 
import pandas as pd, numpy as np 

# Test for serial correlation 
MTS = importr("MTS", lib_loc = "C:/Users/Rami Chehab/Documents/R/win-library/3.3") 
RMTSmq=MTS.mq 

# Create data 
df = pd.DataFrame(np.random.random((108, 2)), columns=['Number1','Number2']) 

# Test for data 
RMTSmq(df, adj=4) 

enter image description here

誰かが私を助けることができますか?可能であれば、グラフをジュピターノートの中にプロットすることができれば幸いです。

はありがとう

答えて

0

これは、のために別の答えであります上記の質問は、上記の質問で提起された議論を正確に使用しています。味むしろ

import rpy2.robjects as ro, pandas as pd, numpy as np 
from rpy2.robjects.packages import importr 

# Call function from R 
import rpy2.robjects as robjects 
from rpy2.robjects import r 
from rpy2.robjects.numpy2ri import numpy2ri 
from rpy2.robjects.packages import importr 

# To plot drawings in R 
grdevices = importr('grDevices') 

# Save the figure as Rami1.png 
grdevices.png(file="Rami1.png", width=512, height=512) 

# We are interested in finding if there is any serial correlation in the Multivariate residuals 
# Since there is a fitting VAR it will be cumbersome to create this function here therefore consider 
# that residauls resi as follow 
resi = pd.DataFrame(np.random.random((108, 2)), columns=['Number1','Number2']) 

# firt take the values of the dataframe to numpy 
resi1=np.array(resi, dtype=float) 

# Taking the variable from Python to R 
r_resi = numpy2ri(resi1) 

# Creating this variable in R (from python) 
r.assign("resi", r_resi) 

# Calling libraries in R for mq to function which is MTS 
r('library("MTS")') 

# Calling a function in R (from python) 
p = ro.r('result <-mq(resi,adj=4)')  
grdevices.dev_off() 

from IPython.display import Image 
Image("Rami1.png") 

enter image description here

0

私は彼の野生のアイデアのための私の偉大な友人サルナスに感謝したいと思います。具体的には、「ウィンドウ内に画像を表示する代わりに、PNG形式や別の画像形式で書き込むことができますか?」と表示されましたか?

それはまさに私がやったことです! のx = -piから(x)は罪のプロットを言って、私はRから数字を表示したいと思い例えば考えてみましょう2PI

import rpy2.robjects as ro 
from rpy2.robjects.packages import importr 

grdevices = importr('grDevices') 


grdevices.png(file="Rami1.png", width=512, height=512) 
p = ro.r('curve(sin, -pi, 2*pi)')  
grdevices.dev_off() 
print() 

from IPython.display import Image 
Image("Rami1.png") 

まで出力が enter image description here

関連する問題