This repository was archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathdependency_tree.py
46 lines (42 loc) · 1.62 KB
/
dependency_tree.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
import numpy as np
import dash
from dash.dependencies import Input, Output
from plotly.graph_objs import *
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
# function to plot
def func(x):
return x[:,0]**2 + np.sin(x[:,1])
# default ranges for x0 & x1
xranges = [[0,1], [-np.pi, np.pi]]
# dropdown to pick which x to plot against
xchooser = dcc.Dropdown(
id='xchooser',
options=[{'label':'x0', 'value':'0'},{'label':'x1', 'value':'1'}],
value='0')
# the user can also modify the ranges manually
minsetter = dcc.Input(id='minsetter', type='number', value=xranges[0][0])
maxsetter = dcc.Input(id='maxsetter', type='number', value=xranges[0][1])
app.layout = html.Div([
html.Div(xchooser, style={'width':'15%'}),
html.Div(['Min: ',minsetter,'Max: ',maxsetter]),
html.Div([dcc.Graph(id='trend_plot')], style={'width':'80%','float':'right'})
])
@app.callback(Output('minsetter','value'),[Input('xchooser','value')])
def set_min(xindex):
return xranges[int(xindex)][0]
@app.callback(Output('maxsetter','value'),[Input('xchooser','value')])
def set_max(xindex):
return xranges[int(xindex)][1]
@app.callback(Output('trend_plot','figure'),
[Input('xchooser','value'),Input('minsetter','value'),Input('maxsetter','value')])
def make_graph(xindex, xmin, xmax):
npt = 20
xgrid = np.zeros((npt,2))
xgrid[:,int(xindex)] = np.linspace(int(xmin), int(xmax), npt)
print('Calling func!')
f = func(xgrid)
return Figure(data=[Scatter(x=xgrid[:,int(xindex)], y=f, mode='markers+lines')])
if __name__ == '__main__':
app.run_server()