36 lines
755 B
Python
36 lines
755 B
Python
|
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()
|