diff --git a/doc/changelog.qmd b/doc/changelog.qmd index aebac1d52..3af3941e6 100644 --- a/doc/changelog.qmd +++ b/doc/changelog.qmd @@ -23,6 +23,8 @@ title: Changelog - 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 >}}) +- Fixed rendering of SVGs in jupyter notebooks. + ## v0.15.2 (2025-12-12) diff --git a/plotnine/_utils/ipython.py b/plotnine/_utils/ipython.py index f2820822b..794b8a547 100644 --- a/plotnine/_utils/ipython.py +++ b/plotnine/_utils/ipython.py @@ -55,6 +55,7 @@ def get_mimebundle( } mimetype = lookup[format] + image: bytes | str = b metadata: dict[str, DisplayMetadata] = {} w, h = figure_size_px if format in ("png", "jpeg"): @@ -62,5 +63,7 @@ def get_mimebundle( elif format == "retina": # `retina=True` in IPython.display.Image just halves width/height metadata = {mimetype: {"width": w // 2, "height": h // 2}} + elif format == "svg": + image = b.decode() - return {mimetype: b}, metadata + return {mimetype: image}, metadata diff --git a/plotnine/typing.py b/plotnine/typing.py index 2fd64b2f5..a71aa9f26 100644 --- a/plotnine/typing.py +++ b/plotnine/typing.py @@ -157,4 +157,6 @@ class DisplayMetadata(TypedDict): height: NotRequired[int] -MimeBundle: TypeAlias = tuple[dict[str, bytes], dict[str, DisplayMetadata]] +MimeBundle: TypeAlias = tuple[ + dict[str, bytes | str], dict[str, DisplayMetadata] +]