HTML plots default to `fig-format: png`, not Quarto 1's `retina`, so plotnine plots come out at half size

Aperta
#1,410 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
66/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, rust

Direzione di ricerca

Start with ExecuteConfig::with_defaults in engine/knitr/format.rs and trace how FigOptions::from_execute applies the figure format across engines. Compare the default environment and rendered image dimensions with the issue’s fig-format: retina reproduction and Quarto 1.9.37 behavior. Done means an unset HTML figure format produces the expected 192 png environment and full-size plotnine output.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

This issue was written by Claude while adding q2 support to
Great Docs. The output shown comes from running each repro.

Bug description

For HTML, Quarto 1's default figure format is retina: its createHtmlFormat sets
execute: { fig-format: "retina" }. The kernel then sees
QUARTO_FIG_FORMAT=png and QUARTO_FIG_DPI=192, which is twice the 96 dpi. Quarto 1 writes each
PNG at half its pixel size, so a plot is sharp on a high-density screen and still 7 × 5 inches
wide.

q2's default is plain png. ExecuteConfig::with_defaults (engine/knitr/format.rs, around
line 299) sets fig_format: Some("png"), which FigOptions::from_execute uses for every engine.
So the kernel sees QUARTO_FIG_DPI=96.

plotnine can't tell png from retina in those variables, so it assumes retina and halves the
dpi (plotnine/_utils/quarto.py, in 0.15.7). It draws a 672 × 480 PNG and shows it at 336 × 240,
half the width Quarto 1 gives it. With fig-width: 4 and fig-height: 3, it's 192 × 144 rather
than 384 × 288.

Setting fig-format: retina gives the Quarto 1 result. Great Docs now sets it for q2 builds when
a site names no figure format.

Steps to reproduce
mkdir figsize && cd figsize
cat > page.qmd <<'QMD'
---
title: Figure size
jupyter: python3
---

```{python}
import os

print(os.environ["QUARTO_FIG_DPI"], os.environ["QUARTO_FIG_FORMAT"])
```

```{python}
from plotnine import ggplot, aes, geom_col
import pandas as pd

ggplot(pd.DataFrame({"x": ["a", "b"], "y": [1, 2]}), aes("x", "y")) + geom_col()
```
QMD
q2 render page.qmd
grep -o '<code>96 png\|<code>192 png' page.html
grep -o '<img[^>]*>' page.html
sips -g pixelWidth -g pixelHeight page_files/figure-html/*.png
Actual behavior

With q2 0.47.0, and with the nightly 0.48.0-nightly.20261125, the environment is 96 png, and:

<img src="page_files/figure-html/cell-2-output-1.png" alt="" width="336" height="240" />

The PNG is 672 × 480 pixels.

With fig-format: retina in the front matter, the environment is 192 png, the image is
width="672" height="480", and the PNG is 1344 × 960.

Expected behavior

As in Quarto 1.9.37, with no fig-format set: the environment is 192 png, and:

<img src="page_files/figure-html/cell-3-output-1.png" width="672" height="480" class="figure-img">

The PNG is 1344 × 960 pixels.

Lingua principale
Rust
Stelle
316
Fork
23
Merge medio
11h 49m
PR unite (30g)
245

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di quarto-dev/q2

Tutte le issue di quarto-dev/q2

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.