I would like to generate a plot using "matplotlib" module and then render then same dynamically onto Flask App. Below code is not rendering the image on the webpage. Which changes do i need to make in the below code so that i can render images dynamically.
Flask APP Code:
from flask import Flask, render_template
import numpy
import matplotlib.pyplot as plt
from io import BytesIO
import base64
app = Flask(__name__)
@app.route('/')
def hello_world():
### Generating X,Y coordinaltes to be used in plot
X = numpy.linspace(0,10,30)
Y = X*X
### Generating The Plot
plt.plot(X,Y)
### Saving plot to disk in png format
plt.savefig('/home/AnandSatya/mysite/square_plot.png')
### Rendering Plot in Html
figfile = BytesIO()
plt.savefig(figfile, format='png')
figfile.seek(0)
figdata_png = base64.b64encode(figfile.getvalue())
result = figdata_png
return render_template('output.html', result=result)
Github path to in Output.html: https://github.com/AnandVetcha/Flask_App/blob/master/templates/output.html