-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlive_visualisations.py
122 lines (109 loc) · 3.3 KB
/
live_visualisations.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import plotly.graph_objects as go
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import pandas as pd
import numpy as np
import plotly.express as px
y_axis_neck, y_axis_knee, y_axis_hip, y_axis_ankle, y_axis_kneey = [0], [0], [0], [0], [0]
x_axis = [0]
exponentiation = np.array([2.718 ** i for i in range(10)])
normaliser = np.sum(exponentiation)
exponentiation = exponentiation / normaliser
global data
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
dcc.Interval(
id='interval-component',
interval=42, # in milliseconds
n_intervals=0
),
html.H1('NECK'),
dcc.Graph(id='neck-graph'),
html.H1('KNEE'),
dcc.Graph(id='knee-graph'),
html.H1('HIP'),
dcc.Graph(id='hip-graph'),
html.H1('ANKLE'),
dcc.Graph(id='ankle-graph'),
html.H1('KNEE-Y'),
dcc.Graph(id='knee-y-graph')
], style={}
)
@app.callback(
Output('neck-graph', 'figure'),
[Input('interval-component', 'n_intervals')])
def make_figure(n):
global y_axis_neck, exponentiation
global x_axis
global data
data = pd.read_csv("data/visual_plotting.csv")
temp_y = np.dot(np.array(data['neck']), exponentiation)
temp_x = x_axis[-1] + 1
if len(x_axis) > 200:
x_axis.pop(0)
y_axis_neck.pop(0)
x_axis.append(temp_x)
y_axis_neck.append(temp_y)
fig = go.Figure()
fig.update_layout(yaxis_range=[0.5, 1.5])
fig.add_trace((go.Scatter(x=x_axis, y=y_axis_neck, name='neck')))
return fig
@app.callback(
Output('knee-graph', 'figure'),
[Input('interval-component', 'n_intervals')])
def make_figure(n):
global y_axis_knee
global x_axis
global data
temp_y = np.dot(np.array(data['knee']), exponentiation)
temp_x = x_axis[-1] + 1
if len(x_axis) > 200:
x_axis.pop(0)
y_axis_knee.pop(0)
x_axis.append(temp_x)
y_axis_knee.append(temp_y)
fig = go.Figure()
fig.update_layout(yaxis_range=[0.5, 3])
fig.add_trace((go.Scatter(x=x_axis, y=y_axis_knee, name='knee')))
return fig
@app.callback(
Output('hip-graph', 'figure'),
[Input('interval-component', 'n_intervals')])
def make_figure(n):
global y_axis_hip
global x_axis
global data
temp_y = np.dot(np.array(data['hip']), exponentiation)
temp_x = x_axis[-1] + 1
if len(x_axis) > 200:
x_axis.pop(0)
y_axis_hip.pop(0)
x_axis.append(temp_x)
y_axis_hip.append(temp_y)
fig = go.Figure()
fig.update_layout(yaxis_range=[0.5, 3])
fig.add_trace((go.Scatter(x=x_axis, y=y_axis_hip, name='knee')))
return fig
@app.callback(
Output('ankle-graph', 'figure'),
[Input('interval-component', 'n_intervals')])
def make_figure(n):
global y_axis_ankle
global x_axis
global data
temp_y = np.dot(np.array(data['ankle']), exponentiation)
temp_x = x_axis[-1] + 1
if len(x_axis) > 200:
x_axis.pop(0)
y_axis_hip.pop(0)
x_axis.append(temp_x)
y_axis_ankle.append(temp_y)
fig = go.Figure()
fig.update_layout(yaxis_range=[0.5, 3])
fig.add_trace((go.Scatter(x=x_axis, y=y_axis_hip, name='knee')))
return fig
if __name__ == '__main__':
app.run_server(debug=True)