-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
49 lines (39 loc) · 1.06 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
from flask import render_template, Flask, request, url_for
import base64
from io import BytesIO
app = Flask("dev")
@app.route("/")
def index():
return render_template("index.html")
@app.route("/submit",methods=["POST"])
def visualize():
try:
x=list(map(float,request.form["xaxis"].split(",")))
y=list(map(float,request.form["yaxis"].split(",")))
except:
return render_template("error.html")
if len(x)!=len(y):
return render_template("error.html")
if len(x)==0 or len(y)==0:
return render_template("error.html")
img=BytesIO()
if request.form["graph"] == "plot" :
plt.figure()
plt.plot(x,y)
plt.title('LINE PLOT')
if request.form["graph"] == "bargraph" :
plt.figure()
plt.bar(x,y)
plt.title('BARGRAPH')
if request.form["graph"] == "scatter" :
plt.figure()
plt.scatter(x,y)
plt.title('SCATTER PLOT')
plt.xlabel('X AXIS')
plt.ylabel('Y AXIS')
plt.grid(True)
plt.savefig(img)
return render_template("submit.html",img=base64.b64encode(img.getvalue()).decode())