add prototype of graph to maxmin route and html

This commit is contained in:
tsb1995 2019-12-22 19:32:57 -08:00
parent 32b7238ab8
commit 905a6e4f54
4 changed files with 19 additions and 2 deletions

Binary file not shown.

19
app.py
View File

@ -2,6 +2,7 @@ from flask import Flask, render_template, request, redirect, Response
from sympy import *
from helpers import apology
import numpy as np
from matplotlib import pyplot as plt
app = Flask(__name__)
@ -144,13 +145,29 @@ def maxmin():
maximum = max(values)
newvar = min(values)
# Create Graph
lam_f = lambdify(x, f, 'numpy')
X = np.linspace(lb-100, ub+100, (ub-lb)*10)
y = lam_f(X)
# plt.figure(figsize=(3,4))
plt.scatter(X, y, c='g', marker='.', )
max_idx = np.argmax(values)
min_idx = np.argmin(values)
plt.plot(candidates[max_idx], values[max_idx], c='r', marker='o', ms=10, label='max')
plt.plot(candidates[min_idx], values[min_idx], c='b', marker='o', ms=10, label='min')
plt.legend()
plt.savefig('static/img/new_plot.png')
plt.close()
# Turn all into latex
value = latex(f)
fprime = latex(fprime)
for i, solution in enumerate(solutions):
solutions[i] = latex(solution)
return render_template("optimized.html", value=value, fprime=fprime, solutions=solutions, lb=lb, ub=ub,
candidates=candidates, newvar=newvar, values=values, maximum=maximum)
candidates=candidates, newvar=newvar, values=values, maximum=maximum,
url='static/img/new_plot.png')
else:
return render_template("maxmin.html")

BIN
static/img/new_plot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -68,7 +68,7 @@
</table>
</font>
<canvas id='myChart' width='400', height='400'></canvas>
<img src={{url}} alt='Chart' height='500' width='500'>