Python:如何在烧瓶中显示sns.catplot()?

时间:2020-09-22 07:49:29

标签: python flask web

由于我是Flask的新手,所以希望有人可以帮助我解决此问题。我无法在Flask中显示我的情节,也不知道是什么问题。 这是我的原始代码:

@app.route("/")
def index():
    """ Returns html with the img tag for your plot.
    """
    return f"""
    <h1>Flask and matplotlib</h1>

    <h3>Plot as a png</h3>
    <img src="/variable.png"
         alt="random points as png"
         height="400"
    >

    """
   
@app.route("/variable.png")
def plot_png():
    """ renders the plot on the fly.
    """
    fig=Figure()
    with sns.axes_style(style='dark'):
        g=sns.catplot("satisfaction", col="Gender", col_wrap=2, data=dft, kind="count", height=2.5, aspect=1.0,
                        palette='Set3')
    plt.show(g)
    output = io.BytesIO()
    FigureCanvasAgg(fig).print_png(output)
    return Response(output.getvalue(), mimetype="image/png")

0 个答案:

没有答案