Skip to content

Commit b4c6c68

Browse files
committed
fix: rendering of SVGs in jupyter notebooks
1 parent 40d4a5c commit b4c6c68

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

doc/changelog.qmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ title: Changelog
2323

2424
- Fixed [](:class:`~plotnine.geom_smooth`) / [](:class:`~plotnine.stat_smooth`) when using a linear model via "lm" with weights for the model to do a weighted regression. This bug did not affect the formula API of the linear model. ({{< issue 1005 >}})
2525

26+
- Fixed rendering of SVGs in jupyter notebooks.
27+
2628
## v0.15.2
2729
(2025-12-12)
2830

plotnine/_utils/ipython.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,15 @@ def get_mimebundle(
5555
}
5656
mimetype = lookup[format]
5757

58+
image: bytes | str = b
5859
metadata: dict[str, DisplayMetadata] = {}
5960
w, h = figure_size_px
6061
if format in ("png", "jpeg"):
6162
metadata = {mimetype: {"width": w, "height": h}}
6263
elif format == "retina":
6364
# `retina=True` in IPython.display.Image just halves width/height
6465
metadata = {mimetype: {"width": w // 2, "height": h // 2}}
66+
elif format == "svg":
67+
image = b.decode()
6568

66-
return {mimetype: b}, metadata
69+
return {mimetype: image}, metadata

plotnine/typing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,6 @@ class DisplayMetadata(TypedDict):
157157
height: NotRequired[int]
158158

159159

160-
MimeBundle: TypeAlias = tuple[dict[str, bytes], dict[str, DisplayMetadata]]
160+
MimeBundle: TypeAlias = tuple[
161+
dict[str, bytes | str], dict[str, DisplayMetadata]
162+
]

0 commit comments

Comments
 (0)