Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The figure size option in the Python chunk is not taken into account for the first chunk #1523

Closed
R-CoderDotCom opened this issue Jan 18, 2024 · 1 comment · Fixed by #1530

Comments

@R-CoderDotCom
Copy link

I am experiencin an issue that might be related to the fix on #1398 available since reticulate 1.31. Now, it seems that fig.size and fig.width are ignored only for the first python chunk.

The following .Rmd will generate the first plot without taking into account the specified sizes:

---
title: "Untitled"
output: html_document
date: "2024-01-17"
---

```{r, echo = FALSE, eval = TRUE}
knitr::opts_chunk$set(fig.height = 4, fig.width = 4)
```

```{python, echo = FALSE}
import matplotlib.pyplot as plt

x = [1, 2, 3]

fig, ax = plt.subplots()
ax.bar(x = x, height = x)
plt.show()
```


```{python, echo = FALSE}
import matplotlib.pyplot as plt

x = [1, 2, 3]

fig, ax = plt.subplots()
ax.bar(x = x, height = x)
plt.show()
```

imagen

But if a chunk is added importing matplotlib or seaborn the sizes will be correct:

---
title: "Untitled"
output: html_document
date: "2024-01-17"
---

```{r, echo = FALSE, eval = TRUE}
knitr::opts_chunk$set(fig.height = 4, fig.width = 4)
```

```{python, echo = FALSE}
import matplotlib.pyplot as plt
```

```{python, echo = FALSE}
import matplotlib.pyplot as plt

x = [1, 2, 3]

fig, ax = plt.subplots()
ax.bar(x = x, height = x)
plt.show()
```


```{python, echo = FALSE}
import matplotlib.pyplot as plt

x = [1, 2, 3]

fig, ax = plt.subplots()
ax.bar(x = x, height = x)
plt.show()
```

imagen

It seems that this trick only works if matpotlib or seaborn is imported. I have tested that empty chunks doesn't work and printing a value doesn't work.

Reticulate version: 1.34.0
Python version: 3.12.1
rmarkdown version: 2.25
knitr version: 1.45

@t-kalinowski
Copy link
Member

Thank you for the detailed bug report! This is fixed now on the development branch.

reticulate::install_github("rstudio/reticulate")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants