graphs.py aangemaakt om grafieken te plotten met matplotlib
This commit is contained in:
parent
334d9a45cd
commit
3f9dd7f927
35
graphs.py
Normal file
35
graphs.py
Normal 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()
|
Reference in New Issue
Block a user