-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
95 lines (74 loc) · 2.77 KB
/
app.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import plotly.graph_objects as go
import dash_bootstrap_components as dbc
import numpy as np
import pandas as pd
app = dash.Dash(__name__, external_stylesheets = [dbc.themes.SUPERHERO])
server = app.server
colors = {
'background': '#1b2e41',
'text': 'lightblue'
}
app.layout = html.Div([
html.Br(),
dcc.Input(id = 'eq', value = 'x', type = 'text'),
html.Br(),
html.Br(),
html.Div(id = 'output-graph'),
html.Br(),
html.P('Double click to switch between scales')], id = 'fallback')
@app.callback(
Output(component_id = 'output-graph', component_property = 'children'),
[Input(component_id = 'eq', component_property = 'value')],
)
def update(eq):
equation = eq[:]
eq = eq.replace('^', '**')
y_range = dict(range = [-5, 5])
x_range = dict(range = [-5, 5])
if 'tan' in eq:
eq = eq[:eq.find('tan'):] + 'np.' + eq[eq.find('tan'):]
x = np.linspace(-4*np.pi, 4*np.pi, 99999)
if 'sin' in eq:
eq = eq[:eq.find('sin'):] + 'np.' + eq[eq.find('sin'):]
x = np.linspace(-4*np.pi, 4*np.pi, 2200)
if 'cos' in eq:
eq = eq[:eq.find('cos'):] + 'np.' + eq[eq.find('cos'):]
x = np.linspace(-4*np.pi, 4*np.pi, 2200)
else:
x = np.linspace(-50, 50, 5000)
y = eval(eq)
df = pd.DataFrame({
'x':x,
'y':y})
fig = go.Figure(
data = [go.Line(
x = df['x'], y = df['y']
)],
layout = {
"autosize":False,
'width':1420,
'height':675,
'title':equation,
'yaxis':y_range,
'xaxis':x_range,
'plot_bgcolor':colors['background'],
'paper_bgcolor': colors['background'],
'font_color':colors['text']
}
)
fig.update_xaxes(showline=True, linewidth=2, linecolor='lightblue',
showgrid = True, gridwidth = 1, gridcolor = '#545454',
zeroline = True, zerolinewidth = 2, zerolinecolor = 'dimgray' )
fig.update_yaxes(showline=True, linewidth=2, linecolor='lightblue',
showgrid = True, gridwidth = 1, gridcolor = '#545454',
zeroline = True, zerolinewidth = 2, zerolinecolor = 'dimgray' )
return dcc.Graph(
id = 'graph',
figure=fig
)
if __name__ == '__main__':
app.run_server()