Skip to content

Python y Reticulate

virtual environments

library(reticulate)
reticulate::use_virtualenv("venv/", T)

Graficos inline

matplotlib

En teoría, si antes se ejecuta lo siguiente en un chink de R, los plots salen más lindos:

knitr::knit_engines$set(python = reticulate::eng_python)

Además, puede ser que para usar matplotlib exitosamente haya que agregar esto:

matplotlib <- reticulate::import("matplotlib")
matplotlib$use("Agg", force = TRUE)

Porque los plot no se mostraban 🤷 y con eso funcionó:

imshow

En mi R/Rstudio, pyplot.imshow() no anda.

Solamente devuelve <matplotlib.image.AxesImage object at 0x7f565c87f1f0>.

Para que aparezca algo, es necesario llamar a pyplot.show() justo después.

Por ejemplo:

import skimage.io as io
import matplotlib as mpl
import matplotlib.pyplot as plt

# mpl.use("Agg", force=True)

img = io.imread("data/BF_Position001.tif.out.tif")
plt.imshow(img, cmap = 'gray')
plt.show()