HexxCube
HexxCube
Mmarimo
Created by HexxCube on 9/29/2024 in #help-support
Show matplotlib inline plot as svg instead of png
The inline matplotlib plots are shown as png and look blurry on my 4k monitor. Increasing the plots dpi only scales it up. Is it possible to display them as a svg instead? I already tried locally changing: marimo/_output/mpl.py
def _internal_show(canvas: FigureCanvasBase) -> None:
buf = io.BytesIO()
buf.seek(0)
canvas.figure.savefig(buf, format="png", bbox_inches="tight")
plt.close(canvas.figure)
mimetype: KnownMimeType = "image/png"
plot_bytes = base64.b64encode(buf.getvalue())
CellOp.broadcast_console_output(
channel=CellChannel.MEDIA,
mimetype=mimetype,
data=build_data_url(mimetype=mimetype, data=plot_bytes),
cell_id=None,
status=None,
)
def _internal_show(canvas: FigureCanvasBase) -> None:
buf = io.BytesIO()
buf.seek(0)
canvas.figure.savefig(buf, format="png", bbox_inches="tight")
plt.close(canvas.figure)
mimetype: KnownMimeType = "image/png"
plot_bytes = base64.b64encode(buf.getvalue())
CellOp.broadcast_console_output(
channel=CellChannel.MEDIA,
mimetype=mimetype,
data=build_data_url(mimetype=mimetype, data=plot_bytes),
cell_id=None,
status=None,
)
to
def _internal_show(canvas: FigureCanvasBase) -> None:
buf = io.BytesIO()
buf.seek(0)
canvas.figure.savefig(buf, format="svg", bbox_inches="tight")
plt.close(canvas.figure)
mimetype: KnownMimeType = "image/svg+xml"
plot_bytes = base64.b64encode(buf.getvalue())
CellOp.broadcast_console_output(
channel=CellChannel.MEDIA,
mimetype=mimetype,
data=build_data_url(mimetype=mimetype, data=plot_bytes),
cell_id=None,
status=None,
)
def _internal_show(canvas: FigureCanvasBase) -> None:
buf = io.BytesIO()
buf.seek(0)
canvas.figure.savefig(buf, format="svg", bbox_inches="tight")
plt.close(canvas.figure)
mimetype: KnownMimeType = "image/svg+xml"
plot_bytes = base64.b64encode(buf.getvalue())
CellOp.broadcast_console_output(
channel=CellChannel.MEDIA,
mimetype=mimetype,
data=build_data_url(mimetype=mimetype, data=plot_bytes),
cell_id=None,
status=None,
)
but it still shows up as a png.
3 replies