boris@boris-All-Series:~/FLASKHTML$ ls -CRl
.:
total 20
-rw-rw-r-- 1 boris boris 1559 авг 7 19:15 flaskMatplotlib10.py
-rw-rw-r-- 1 boris boris 1653 авг 7 19:15 flaskMatplotlib12.py
-rw-rw-r-- 1 boris boris 2060 авг 7 19:15 flaskMatplotlib9.py
drwxrwxr-x 2 boris boris 4096 авг 7 19:21 __pycache__
drwxrwxr-x 2 boris boris 4096 авг 7 19:15 templates
./__pycache__:
total 4
-rw-rw-r-- 1 boris boris 1807 авг 7 19:21 flaskMatplotlib12.cpython-38.pyc
./templates:
total 4
-rw-rw-r-- 1 boris boris 162 авг 7 19:15 download.html
boris@boris-All-Series:~/FLASKHTML$ cat flaskMatplotlib12.py
import io
from flask import Response, render_template
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from flask import Flask
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats
import warnings
warnings.filterwarnings('ignore')
plt.rcParams["figure.figsize"] = [15.50, 11.50]
plt.rcParams["figure.autolayout"] = True
app = Flask(__name__)
@app.route('/')
def upload_form():
return render_template('download.html')
@app.route('/print-plot')
def plot_png():
fig = Figure()
axes = fig.add_subplot(1, 1, 1)
axes.set_title('Verification CLT via flask&&matplotlib, Refresh Screen a couple of times',fontsize = 15, color = 'black')
n = 10000
longlst = []
sigmalst = []
lst = ["avg","avg1","avg2","avg3"]
for avs in lst:
avs = []
for i in range(1,n):
a = np.random.randint(1,7,10)
avs.append(np.average(a))
# Normalise this histogram too
axes.hist(avs[0:], 20, density=True, stacked=True)
longlst = longlst + avs[0:]
sigmalst = sigmalst + avs[:]
zscore = stats.zscore(longlst)
mu, sigma = np.mean(sigmalst), np.std(sigmalst)
s = np.random.normal(mu, sigma, 10000)
# Create the bins and histogram
count, bins, ignored = axes.hist(s, 20, density=True, stacked=True)
# Use scipy.stats implementation of the normal pdf
# Plot the distribution curve
x = np.linspace(1.5, 6.5, num=100)
axes.plot(x, stats.norm.pdf(x, mu, sigma))
output = io.BytesIO()
FigureCanvas(fig).print_png(output)
return Response(output.getvalue(), mimetype='image/png')
boris@boris-All-Series:~/FLASKHTML$ cat templates/download.html
<!doctype html>
<title>Python Flask File Generate Gauss CLT Report </title>
<p>
<h2><a href="{{ url_for('.plot_png') }}">Display Gaussian plots</a></h2>
</p>
No comments:
Post a Comment