`to_png()` static export loses title/subtitle/axis ticks/labels/legend when a layer uses `linetype=0`

オープン
#1,509 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
62/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
kotlin, python

調査の方向性

ggplot.to_png() または ggsave(..., format="png") から到達する静的エクスポートパスから始め、_repr_html() と比較します。linetype=0 を使用して、最小限の geom_segment ケースを再現します。そのパラメーターがレンダリングにどのような影響を与えるかを追跡し、PNG がタイトル、サブタイトル、軸、グリッド線、凡例を保持し、コネクターだけを非表示にすることを確認します。

索引モデルが issue の本文から書いたものです。

説明

Summary

I have been experiencing an odd behavior when a plot contains any layer with linetype=0 (I have been using this "trick" to annotate (think markers of interesting things) my plots by making a line invisible while still showing e.g. an arrowhead via arrow=... - this is legacy code that I have built upon, I am certain there might be better ways nowadays), the static PNG export (ggplot.to_png() / ggsave(..., format="png"), Only the raw geometry (bars, points, the visible arrowhead, etc.) is drawn.

The interactive HTML/JS rendering (_repr_html_(), browser display) is not affected — the plot renders correctly there. This makes the bug easy to miss during development (e.g. in Jupyter or a web app preview) and only surface when exporting a static image (e.g. for embedding into PowerPoint, PDF, or email reports).

Environment

  • lets-plot version: 4.11.0
  • OS: Linux (reproduced in a headless container)
  • Python: 3.12

Minimal Reproduction

The following code is a derivation

from io import BytesIO
import pandas as pd
import lets_plot as lp

df = pd.DataFrame({
    "x": ["A", "B", "C", "D"],
    "y": [10, 20, 15, 25],
})

# BROKEN: linetype=0 on geom_segment wipes out title/subtitle/axis ticks/labels/legend
p_broken = (
    lp.ggplot(df, lp.aes(x="x", y="y"))
    + lp.geom_bar(stat="identity")
    + lp.theme_bw()
    + lp.labs(title="Title is missing", subtitle="Subtitle is missing too",
              x="X axis label missing", y="Y axis label missing")
    + lp.ggsize(800, 500)
    + lp.geom_segment(x=2, y=25, xend=3, yend=25, linetype=0, arrow=lp.arrow(type="closed"))
)
with open("broken.png", "wb") as f:
    p_broken.to_png(f)

# WORKING: identical plot, only difference is the segment keeps its default linetype
p_ok = (
    lp.ggplot(df, lp.aes(x="x", y="y"))
    + lp.geom_bar(stat="identity")
    + lp.theme_bw()
    + lp.labs(title="Title is missing", subtitle="Subtitle is missing too",
              x="X axis label missing", y="Y axis label missing")
    + lp.ggsize(800, 500)
    + lp.geom_segment(x=2, y=25, xend=3, yend=25, arrow=lp.arrow(type="closed"))
)
with open("ok.png", "wb") as f:
    p_ok.to_png(f)

Expected Result

Both broken.png and ok.png should render identically apart from the visibility of the connecting line segment (hidden vs. visible), i.e. both should show:

  • Title: "Title is missing"
  • Subtitle: "Subtitle is missing too"
  • X axis label + tick labels (A, B, C, D)
  • Y axis label + tick labels (0-25)
  • Gridlines from theme_bw()

Actual Result

  • ok.png (no linetype=0): renders correctly — title, subtitle, axis ticks/labels, gridlines all present.
Image
  • broken.png (with linetype=0 on the geom_segment layer): title, subtitle, axis ticks, axis labels, and gridlines are all missing. Only the bare bar geometry (and the arrowhead) is drawn on a blank canvas.
Image

Additional Notes

  • This issue shall not serve as a canvas to argue about the actual purpose of the borderline edgecase of linetype=0 on a segment geometry. It shall purely show the unexpected behavior of basically destroying any plot information such as title, subtitle, labels, ticks, etc.
  • The interactive/HTML rendering path (_repr_html_()) renders p_broken correctly — this appears to be isolated to the static Skia PNG export path only.
  • We discovered this while exporting plots with an "arrow pointing at the last data point" annotation pattern:
    lp.geom_segment(x=x0, y=y0, xend=x1, yend=y1, arrow=lp.arrow(type="closed"), linetype=0, show_legend=False)
    
    which is a common idiom for hiding the connecting line while keeping only the arrowhead visible. Removing linetype=0 (accepting a visible connector line, or using an alternative to hide it, e.g. alpha=0 — untested) avoids the bug.
  • Bisection confirmed:
    • arrow=... alone: not the cause.
    • fill="white" on the segment: not the cause.
    • linetype=0: is the cause — removing only this parameter (keeping everything else identical) fixes the export.
  • This was reproduced consistently across multiple real-world plots (bar charts with theme_bw(), discrete x-axis with 50+ categories, ggtb() toolbar, legend from scale_fill_manual()), not just the minimal example above, so it does not appear to depend on plot complexity/data volume — the minimal repro triggers it with a trivial 4-row dataset.

Impact

Any application that exports lets-plot charts to static images (PNG/PDF/PPTX embedding, etc.) using this common "hide line, show arrow" pattern will silently produce images missing critical context (title, axis meaning, legend), which can be misleading in reports/dashboards if not caught visually.

主要言語
Kotlin
スター
1.8k
フォーク
63
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

JetBrains/lets-plot のほかの issue

JetBrains/lets-plot の issue をすべて見る

似ている issue

Kotlin の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。