![]() This will work: plt.imshow(my_image, cmap='gray') It will be rendered and can be compiled into HTML / PDF using knitr. This means that the familiar plt.show() and plt.imshow() will work without any extra work. Users/Samuel/.virtualenvs/r-tensorflow/bin/pythonĪdd a Python chunk (not R!) in your R Markdown document (see attached screenshot) and you can now write native Python code. Numpy: /Users/Samuel/anaconda3/lib/python3.6/site-packages/numpy Pythonhome: /Users/Samuel/anaconda3:/Users/Samuel/anaconda3 Libpython: /Users/Samuel/anaconda3/lib/libpython3.6m.dylib You should expect to see that your session is configured with the settings you specified: python: /Users/Samuel/anaconda3/bin/python Use_python('/Users/Samuel/anaconda3/bin/python') # change the following to point to the desired path on your system ![]() That is the reason why it's important to do this, to make sure Rstudio will use the specified python instance where your matplotlib library (and the other libraries you will be using for that project) can be found: library(reticulate) The default python that comes shipped with most OS is usually the outdated python 2 and is not where you install your packages. ![]() You want to insert an R chunk, and run the following code to configure the path to the version of Python you want to use. My answer is a little late but I hope it's a thorough walkthrough of doing it the right way - not rendering it and then loading it as a png but have the python code executed more "natively". You can do that with reticulate, but most time in trying to follow a tutorial in doing that you may encounter some technicalities that weren't sufficiently explained. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |