Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

369
Visualizações
Cross-reference a python code chunk in Rmarkdown with reticulate

I have a Rmarkdown document containing some python code chunks using the reticulate library. The code executes output perfectly; however, how would I cross-reference the generated plots in the text using its label? I am using bookdown::pdf_documents2 etc, and have no issue with inline reference of R chunks using the standard \@ref(fig:my-plot).

An MWE would be:


```{python, my-plot}
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(10)
y = np.arange(10)
plt.figure()
plt.plot(x, y)
plt.show()
```

In Figure \@ref(fig:my-plot)....


I have tried without prepending the chunk type (fig, etc.)

I understand I can save the image to file and include it with knitr as a subsequent R chunk, but it would be preferable to do it through the python chunk alone.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I must have been making an error when previously attempting fig.cap within the chunk, as Daniel correctly suggests in the question comments. Attempting with this again, I can cross-reference perfectly with the python chunk across all HTML, PDF and word outputs. The updated MWE is:

```{python, my-plot, fig.cap="My Caption"}
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(10)
y = np.arange(10)
plt.figure()
plt.plot(x, y)
plt.show()
```

In Figure \@ref(fig:my-plot)...


Each of the outputs in the YAML header required the varying bookdown:: options. For PDF (bookdown::pdf_document2), for word (bookdown::word_document2) and Rmdformats in my case, the option of use_bookdone: true.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda