1

graphs.py aangemaakt om grafieken te plotten met matplotlib

This commit is contained in:
Ventilaar 2021-01-11 16:23:23 +01:00
parent 334d9a45cd
commit 3f9dd7f927

35
graphs.py Normal file
View File

@ -0,0 +1,35 @@
from matplotlib.backends.backend_svg import FigureCanvasSVG
from matplotlib.backends.backend_agg import FigureCanvasAgg
from matplotlib.figure import Figure
import numpy as np
import random
import io
import math
def random_plot():
fig = Figure()
axis = fig.add_subplot(1, 1, 1)
randint = random.randint(1, 50)
x = np.arange(randint, random.randint(randint, randint+50), 0.05)
y = np.tan(math.pi*x)
axis.plot(x, y)
output = io.BytesIO()
FigureCanvasSVG(fig).print_svg(output)
return output.getvalue()
def plot_xy(x, y):
fig = Figure(figsize=(32, 18))
axis = fig.add_subplot(1, 1, 1)
axis.plot(x, y)
output = io.BytesIO()
FigureCanvasAgg(fig).print_png(output)
return output.getvalue()