-
Notifications
You must be signed in to change notification settings - Fork 390
Description
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
quarto-cli/src/resources/jupyter/notebook.py
Lines 106 to 114 in 83a3b5a
| 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"] |
quarto-cli/src/resources/jupyter/notebook.py
Lines 181 to 182 in 83a3b5a
| # 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"]}')
```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

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.
