yihui / knitr

A general-purpose tool for dynamic report generation in R
https://yihui.org/knitr/
2.38k stars 876 forks source link

Unable to get python-matplotlib plots to render as PNG #2182

Closed deto closed 2 years ago

deto commented 2 years ago

I'm trying to knit an html document with a python code block and the python plots will only render as SVG despite me setting the device as "png". I've tried setting the device both in the chunk header and in the chunk defaults. Is this device setting not applicable to plots coming out of Python and, if so, how is the format for those plots selected? Thanks!

---
title: "Testing R Markdown"
output: html_document
---

```{r setup}
knitr::opts_chunk$set(dev = "png")
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(9, 5))
plt.plot(
    [1, 2, 3, 4, 5],
    [4, 2, 5, 2, 4]
)
plt.show()


<!--
Please keep the below portion in your issue. Your issue will be closed if any of the boxes is not checked (i.e., replace `[ ]` by `[x]`). In certain (rare) cases, you may be exempted if you give a brief explanation (e.g., you are only making a suggestion for improvement). Thanks!
-->

---

By filing an issue to this repo, I promise that

- [x] I have fully read the issue guide at https://yihui.org/issue/.
- [x] I have provided the necessary information about my issue.
    - If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    - If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included `xfun::session_info('knitr')`. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: `remotes::install_github('yihui/knitr')`.
    - If I have posted the same issue elsewhere, I have also mentioned it in this issue.
- [x] I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.
deto commented 2 years ago

Nevermind. Issue was with reticulate and upgrading from 1.20 to 1.26 fixed it.

github-actions[bot] commented 1 year ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.