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

Figure option for size in python chunk are taken into account once #1398

Closed
cderv opened this issue Jun 22, 2023 · 2 comments
Closed

Figure option for size in python chunk are taken into account once #1398

cderv opened this issue Jun 22, 2023 · 2 comments

Comments

@cderv
Copy link
Contributor

cderv commented Jun 22, 2023

Following a report at quarto-dev/quarto-cli#6008

---
title: "fig-width test"
output: html_document
---

## Make a Wide Python Plot

```{python}
#| fig.width: 8
#| fig.height: 2
import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.show()
```

## Make a Square Python Plot

```{python}
#| fig.width: 3
#| fig.height: 3
plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.show()
```

image

Possibly related to #1140

It seems the options are taken into account once only. Is there a specific way to reset the matplotlib initialization ?

reticulate/R/knitr-engine.R

Lines 476 to 477 in 9163ac3

# set up figure dimensions
plt$rc("figure", figsize = tuple(options$fig.width, options$fig.height))

Is this a limitation ? Or something we can improve ?

@t-kalinowski
Copy link
Member

Thanks for reporting @cderv! A fix is in the works (on a PR branch currently), should be merged into main soon.

t-kalinowski added a commit to matthew-brett/reticulate that referenced this issue Jun 26, 2023
- reset matplot fig size each chunk
closes rstudio#1398

- call plt.close() instead of plt.clf() to ensure that plt.get_fignums() is cleared and so we can easily avoid calling plt.show() too many times.
@cderv
Copy link
Contributor Author

cderv commented Jun 27, 2023

Thanks !

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

No branches or pull requests

2 participants