-
Notifications
You must be signed in to change notification settings - Fork 1
/
1-AGE-LDL.py
239 lines (119 loc) · 3.79 KB
/
1-AGE-LDL.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/env python
# coding: utf-8
# In[1]:
#!pip install -U holoviews
#!pip install -U bokeh
#!pip install -U plotly
# In[2]:
import bokeh
#bokeh.sampledata.download()
print("done")
from bokeh.plotting import figure, output_notebook, show
output_notebook()
# In[3]:
import bokeh
bokeh.__version__
# In[4]:
import pandas as pd
import numpy as np
import holoviews as hv
from bokeh.io import curdoc
from bokeh.layouts import layout
from bokeh.models import Slider, Button
from bokeh.sampledata import gapminder
from holoviews import dim
from holoviews import opts
from holoviews.plotting.bokeh import BokehRenderer
# In[5]:
l = ["#40fe10","#fffe10","#f25000","#ff0f00"]
# ### Gapminder test
# In[6]:
renderer = hv.renderer('bokeh')
hv.extension('plotly')
hv.extension('bokeh')
# In[7]:
df = pd.read_csv("/home/atez/Scrivania/web valley/milano_cleaned.csv")
# In[25]:
#print(df.columns.values)
# In[9]:
df_medical = df[['cod_pz','visit:visit','ana:age','lab:calculated_ldl','ScoreClass']]
# ### Traiettorie
# In[10]:
df_Trajectories = pd.read_csv("/home/atez/Scrivania/web valley/traj.csv", sep = ' ')
# In[11]:
df_medical.index = df_medical['cod_pz']
df_Trajectories.index = df_Trajectories['ID']
# In[12]:
df_Trajectories.head()
# In[13]:
gapminder_df = df_medical.join(df_Trajectories)
# ### Gruoped
# In[14]:
agr_1 = gapminder_df.groupby(['visit:visit','code'])[['ana:age','lab:calculated_ldl','ScoreClass']].median()
agr_2 = gapminder_df.groupby(['visit:visit','code'])['cod_pz'].count()
# In[15]:
df_group = agr_1.join(agr_2)
# In[16]:
df_group.reset_index(inplace=True)
# ### HV
# In[17]:
ds = hv.Dataset(df_group)
# In[24]:
# Apply dimension labels and ranges
kdims = ['ana:age', 'lab:calculated_ldl']
#vdims = ['Country', 'Population', 'Group']
vdims = ['code', 'cod_pz', 'ScoreClass']
dimensions = {
'ana:age' : dict(label='Age', range=(30,100)),
'lab:calculated_ldl' : dict(label='LDL', range=(40, 300)),
'cod_pz': ('Numero Pazineti', 'cod_pz')
}
# In[19]:
# Create Points plotting age vs sbp indexed by visit
gapminder_ds = ds.redim(**dimensions).to(hv.Points, kdims, vdims, 'visit:visit')
# Define annotations
text = gapminder_ds.clone({yr: hv.Text(1.2, 25, str(int(yr)), fontsize=30)
for yr in gapminder_ds.keys()})
# In[20]:
hvgapminder = (gapminder_ds * text).opts(
opts.Points(alpha=0.5, color='ScoreClass', cmap = l, line_color='black',
size=np.sqrt((dim('cod_pz'))*20), width=1200, height=800,
tools=['hover'], title='Graph of the correlation between age and blod pressure, grouped by degeneration of the disease.'),
opts.Text(text_font_size='52pt', text_color='lightgray'))
# In[21]:
# Define custom widgets
def animate_update():
year = slider.value + 1
if year > end:
year = start
slider.value = year
# In[22]:
# Update the holoviews plot by calling update with the new year.
def slider_update(attrname, old, new):
hvplot.update((new,))
callback_id = None
def animate():
global callback_id
if button.label == '► Play':
button.label = '❚❚ Pause'
callback_id = doc.add_periodic_callback(animate_update, 200)
else:
button.label = '► Play'
doc.remove_periodic_callback(callback_id)
start = 0;
end = 3;
slider = Slider(start=start, end=end, value=start, step=1, title='Visit')
slider.on_change('value', slider_update)
button = Button(label='► Play', width=60)
button.on_click(animate)
# In[23]:
# Get HoloViews plot and attach document
doc = curdoc()
hvplot = renderer.get_plot(hvgapminder, doc)
hvplot.update((1964,))
# Make a bokeh layout and add it as the Document root
plot = layout([[hvplot.state], [slider, button]], sizing_mode='fixed')
doc.add_root(plot)
# In[ ]:
# In[ ]:
# In[ ]: