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

Đang mở
#1,410 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
66/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, rust

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Rust
Star
316
Fork
23
Merge trung bình
11 giờ 49 phút
Pull request đã merge (30 ngày)
245

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của quarto-dev/q2

Tất cả issue của quarto-dev/q2

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.