Plotting png plot from matplotlib in flask displays raw data Plotting png plot from matplotlib in flask displays raw data flask flask

Plotting png plot from matplotlib in flask displays raw data


It turns out that base64 encoding was necessary:

    fig, ax = plt.subplots(1)    plt.plot(np.arange(100), np.random.normal(0, 1, 100))    img = BytesIO()    fig.savefig(img)    img.seek(0)    resp = Response(response=base64.b64encode(img.getvalue()),                    status=200, mimetype="image/png")    return resp