Skip to content

Commit 32ce9b5

Browse files
authored
Return html encoded matplotlib Figure from msgspec encoder hook (#9359)
## 📝 Summary <!-- If this PR closes any issues, list them here by number (e.g., Closes #123). Detail the specific changes made in this pull request. Explain the problem addressed and how it was resolved. If applicable, provide before and after comparisons, screenshots, or any relevant details to help reviewers understand the changes easily. --> This fix changes the msgspec encoder hook to actually return encoded matplotlib Figure objects – like it's already done for matplotlib Axes objects. ## 📋 Pre-Review Checklist <!-- These checks need to be completed before a PR is reviewed --> - [x] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on [Discord](https://marimo.io/discord?ref=pr), or the community [discussions](https://github.com/marimo-team/marimo/discussions) (Please provide a link if applicable). - [x] Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it. - [x] Video or media evidence is provided for any visual changes (optional). <!-- PR is more likely to be merged if evidence is provided for changes made --> ## ✅ Merge Checklist - [x] I have read the [contributor guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md). - [x] Documentation has been updated where applicable, including docstrings for API changes. - [x] Tests have been added for the changes made. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes the `msgspec` encoder hook to return HTML-encoded data for `matplotlib.figure.Figure` objects. This matches the existing `Axes` handling so figures render correctly and serialize without errors. <sup>Written for commit 21fa169. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. -->
1 parent c0df102 commit 32ce9b5

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

marimo/_messaging/msgspec_encoder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def enc_hook(obj: Any) -> Any:
170170
if isinstance(obj, matplotlib.figure.Figure):
171171
html = as_html(vstack([str(obj), obj]))
172172
mimetype, data = html._mime_()
173+
return {"mimetype": mimetype, "data": data}
173174

174175
if isinstance(obj, Axes):
175176
html = as_html(vstack([str(obj), obj]))

0 commit comments

Comments
 (0)