Graphing matplotlib with Python code in a R Markdown document

前端 未结 4 1348
半阙折子戏
半阙折子戏 2021-01-11 09:14

Is it possible to use Python matplotlib code to draw graph in RStudio?

e.g. below Python matplotlib code:

import numpy as np
import matplotlib.pyplot         


        
4条回答
  •  别那么骄傲
    2021-01-11 09:42

    1. install.packages('devtools') first, get install_github function
    2. install_github("rstudio/reticulate") install the dev version of reticulate
    3. in r markdown doc, use code below to enable the function.
    ```{r setup, include=FALSE}  
    library(knitr)  
    library(reticulate)  
    knitr::knit_engines$set(python = reticulate::eng_python)  
    ```
    

    Try it , you will get what you want and don't need to save any image.

    Imgur

提交回复
热议问题