Matplotlib figure as SVG with Shiny for Python

I'm interested in rendering matplotlib figures as SVG rather than PNG because the labels and titles in the following app seems unsharp/blurry to me.

from shiny import *
import matplotlib.pyplot as plt

app_ui = ui.page_fluid(
    ui.output_plot("dens_plot"),
    ui.input_slider(id = "n", label = "slider", min = 10, max = 50, value = 10)
)

def server(input, output, session):
    @output
    @render.plot()
    def dens_plot():
        xs = list(range(input.n()+1))
        ys = [1]*len(xs)
        fig, ax = plt.subplots()
        ax.stem(xs, ys , markerfmt = " ")
        ax.set_xlabel("X title")
        ax.set_ylabel("Y title")
        return fig

app = App(app_ui, server)

I tried @render.plot(format = "svg") but it seems like a different option was already passed as I'm getting:

TypeError: matplotlib.figure.Figure.savefig() got multiple values for keyword argument 'format'

How can I achieve this?

It seems that the try_render_matplotlib() function has hardcoded format="png" so it's not possible to override this by specifying it via render.plot().

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.