-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreproduce_error.py
75 lines (65 loc) · 1.77 KB
/
reproduce_error.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
from typing import Iterable, Optional
import numpy as np
import plotly.graph_objects as go
from dash import Dash, Input, Output, dcc, html
def edge_pos(pos: Iterable[float]) -> list[Optional[float]]:
res = []
for start_pos in pos:
for end_pos in pos:
res.extend([start_pos, end_pos, None])
return res
app = Dash()
app.layout = html.Div(
[
html.Button(id="button", children="Click me!", n_clicks=0),
dcc.Graph(
id="figure",
style={"flex": 1},
),
],
style={
"display": "flex",
"position": "fixed",
"width": "100%",
"height": "100%",
},
)
@app.callback(Output("figure", "figure"), Input("button", "n_clicks"))
def update_fig(n_clicks: int) -> go.Figure:
# Randomly generate points from a standard normal
x, y = np.random.normal(0, 1, size=(2, 5))
# Create the trace for nodes
node_trace = go.Scatter(x=x, y=y, mode="markers")
# Create a trace of lines connecting them
n_clicks = n_clicks / 100
edge_trace = go.Scatter(
name=str(np.random.normal(0, 1)),
x=[
0,
np.cos(n_clicks) - np.sin(n_clicks),
None,
0,
-np.cos(n_clicks) - np.sin(n_clicks),
None,
],
y=[
0,
np.cos(n_clicks) + np.sin(n_clicks),
None,
0,
np.cos(n_clicks) - np.sin(n_clicks),
None,
],
mode="lines",
)
traces = [edge_trace]
# if n_clicks % 2:
# traces.append(edge_trace)
fig = go.Figure(
data=[*traces],
)
fig.update_xaxes(range=[-1, 1])
fig.update_yaxes(range=[-1, 1])
return fig
if __name__ == "__main__":
app.run_server(debug=True)