File size: 2,195 Bytes
c162999
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import gradio as gr
import numpy as np
import matplotlib.pyplot as plt
from scipy import special as sp


def plot_function(function_name, x_min, x_max, y_min, y_max):
    functions = {
        "abs": np.abs,
        "acos": np.arccos,
        "acosh": np.arccosh,
        "airy": sp.airy,
        "asin": np.arcsin,
        "asinh": np.arcsinh,
        "atan": np.arctan,
        "atanh": np.arctanh,
        "ceil": np.ceil,
        "cos": np.cos,
        "cosh": np.cosh,
        "erf": lambda x: np.vectorize(sp.erfi)(x).real,
        "erfc": lambda x: np.vectorize(sp.erfi)(x).imag,
        "exp": np.exp,
        "floor": np.floor,
        "imag": np.imag,
        "int": lambda x: np.vectorize(int)(x),
        "inverf": lambda x: np.vectorize(sp.erfi)(x).real,
        "invnor": lambda x: np.vectorize(sp.erfi)(x).imag,
        "lambertw": lambda x: np.vectorize(sp.lambertw)(x).real,
        "log": np.log,
        "log10": np.log10,
        "real": np.real,
        "sgn": lambda x: np.sign(x),
        "sin": np.sin,
        "sinh": np.sinh,
        "sqrt": np.sqrt,
        "tanh": np.tanh,
        "jv": sp.jv,
        "EllipticK": sp.ellipk,
        "EllipticE": sp.ellipe,
        "erfi": sp.erfi,
        "gamma": sp.gamma,
        "tan": np.tan
    }
    x = np.linspace(x_min, x_max, 1000)
    y = functions[function_name](x)
    plt.ylim(y_min, y_max)
    plt.plot(x, y)
    plt.title(function_name)
    plt.xlabel('x')
    plt.ylabel('y')
    plt.grid(True)
    plt.tight_layout()

    return plt.gcf()

evals = ["abs", "acos", "acosh", "airy", "asin", "asinh", "atan", "atanh", "cdawson", "ceil", "cerf", "cos", "cosh", "erf", "erfc", "exp", "floor", "imag", "int", "inverf", "invnor", "lambertw", "lgamma", "log", "log10", "real", "sgn", "sin", "sinh", "sqrt", "tanh", "jv", "besj0", "besj1", "besy0", "EllipticK", "EllipticE", "besy1", "erfi", "gamma", "tan"]

inputs = [
    gr.Dropdown(choices=evals),
    gr.Number(0, label="x min"),
    gr.Number(1, label="x max"),
    gr.Number(0, label="y min"),
    gr.Number(1, label="y max"),
]
iface = gr.Interface(
    title='gnuplot',
    fn=plot_function,
    inputs=inputs,
    outputs="plot",
    live=True
)
iface.launch()