As @d parolin pointed out, the figure generated by matplotlib
will need to be saved before being rendered by the HTML. In order to serve images in flask
by HTML, you will need to store the image in your flask
file directory:
static/
images/
plot.png --> store plots here
templates/
Therefore, in your application, use plt.savefig
:
@app.route('/test')
def chartTest():
lnprice=np.log(price)
plt.plot(lnprice)
plt.savefig('/static/images/new_plot.png')
return render_template('untitled1.html', name = 'new_plot', url ='/static/images/new_plot.png')
Then in untitled1.html
:
<p>{{ name }}</p>
<img src={{ url}} alt="Chart" height="42" width="42">