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

QUARTO_FIG_* environment variable are not updated when configuration values changes and kernel is opened. #11713

Open
cderv opened this issue Dec 19, 2024 · 0 comments
Labels
bug Something isn't working jupyter

Comments

@cderv
Copy link
Collaborator

cderv commented Dec 19, 2024

I noticed that with figure value as our doc at https://quarto.org/docs/computations/execution-options.html#figure-options says

You can change the default sizes using the fig-width and fig-height options
(...)
For Python, these values are used to set the Matplotlib figure.figsize rcParam (you can of course manually override these defaults for any given plot).
(...)
If you are using another graphics library with Jupyter and want to utilize these values, you can read them from QUARTO_FIG_WIDTH and QUARTO_FIG_HEIGHT environment variables.

The problem seems to be that we do set env var for the kernel
And this is a problem for all values set

def set_env_vars(options):
os.environ["QUARTO_FIG_WIDTH"] = str(options["fig_width"])
os.environ["QUARTO_FIG_HEIGHT"] = str(options["fig_height"])
if options["fig_format"] == "retina":
os.environ["QUARTO_FIG_DPI"] = str(options["fig_dpi"] * 2)
os.environ["QUARTO_FIG_FORMAT"] = "png"
else:
os.environ["QUARTO_FIG_DPI"] = str(options["fig_dpi"])
os.environ["QUARTO_FIG_FORMAT"] = options["fig_format"]

# set environment variables
set_env_vars(quarto_kernel_setup_options)

But we probably don't force a restart if the value change.

Run this once with Jupyter kernel not open
quarto render index.qmd --execute-daemon-restart

---
title: 'Fig size'
format: html
---

```{python}
import os
print(f'QUARTO_FIG_WIDTH: {os.environ["QUARTO_FIG_WIDTH"]}')
print(f'QUARTO_FIG_HEIGHT: {os.environ["QUARTO_FIG_HEIGHT"]}')
print(f'QUARTO_FIG_DPI: {os.environ["QUARTO_FIG_DPI"]}')
print(f'QUARTO_FIG_FORMAT: {os.environ["QUARTO_FIG_FORMAT"]}')
```

```{python}
# Get the value of figure.figsize
import matplotlib.pyplot as plt
print(f'Default figure size: {plt.rcParams["figure.figsize"]}')
print(f'Default figure size: {plt.rcParams["figure.dpi"]}')
```

Image

Now modify the YAML header and re-render with the keep-alive kernel

---
title: 'Fig size'
format:
  html: 
    fig-width: 1
    fig-height: 2
    fig-dpi: 450
    fig-format: svg
---

```{python}
import os
print(f'QUARTO_FIG_WIDTH: {os.environ["QUARTO_FIG_WIDTH"]}')
print(f'QUARTO_FIG_HEIGHT: {os.environ["QUARTO_FIG_HEIGHT"]}')
print(f'QUARTO_FIG_DPI: {os.environ["QUARTO_FIG_DPI"]}')
print(f'QUARTO_FIG_FORMAT: {os.environ["QUARTO_FIG_FORMAT"]}')
```

```{python}
# Get the value of figure.figsize
import matplotlib.pyplot as plt
print(f'Default figure size: {plt.rcParams["figure.figsize"]}')
print(f'Default figure size: {plt.rcParams["figure.dpi"]}')
```

Matplot lib config is updated, but not the environment variable
Image

As the environment variable are meant to be used by other graphic package in python not using matplotlib, I think they should be updated if possible, or the configuration change should trigger a restart of the kernel.

@cderv cderv added the jupyter label Dec 19, 2024
@mcanouil mcanouil added the bug Something isn't working label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working jupyter
Projects
None yet
Development

No branches or pull requests

2 participants