the ABSeas- altair, bokeh and seaborn
Posted on Sat 15 April 2017 in Projects
In [42]:
import pandas as pd
import numpy as np
from bokeh.models import GMapPlot, GMapOptions, ColumnDataSource, Circle, Range1d, PanTool, WheelZoomTool, ResetTool, SaveTool
from bokeh.plotting import figure, output_file, show
from bokeh.io import show, output_notebook
from bokeh.embed import file_html
output_notebook()
import altair as alt
import seaborn as sns
import matplotlib.pyplot as plt
In [43]:
df_lap1 = pd.read_csv('unpublished/zipped_csv/saita_natTT_lap1.csv')
df_lap2 = pd.read_csv('unpublished/zipped_csv/saita_natTT_lap2.csv')
df_lap3 = pd.read_csv('unpublished/zipped_csv/saita_natTT_lap3.csv')
frames = [df_lap1, df_lap2, df_lap3]
df_all = pd.concat(frames, keys=['lap1','lap2','lap3'])
In [44]:
df_lap3.head()
Out[44]:
In [45]:
df_all.loc['lap1'].head()
Out[45]:
In [36]:
data = df_all
In [37]:
data.loc['lap3'].reset_index().iloc[2:].head()
Out[37]:
In [38]:
mid_lat = data['latitude'].min()+((data['latitude'].max()-data['latitude'].min())/2)
mid_lon = data['longitude'].min()+((data['longitude'].max()-data['longitude'].min())/2)
map_options = GMapOptions(lat=mid_lat, lng=mid_lon, map_type="roadmap", zoom=13)
activitymap = GMapPlot(x_range=Range1d(), y_range=Range1d(), map_options=map_options)
activitymap.api_key = "AIzaSyBcIU6DrIyKGVxKJHbL8lgm0YMyj7UEAvU"
source = ColumnDataSource(data=data)
circle = Circle(x="longitude", y="latitude", size=3)
activitymap.add_glyph(source, circle)
activitymap.add_tools(PanTool(), WheelZoomTool(), ResetTool(), SaveTool())
output_file("example.html")
In [39]:
show(activitymap)
In [10]:
data.loc['lap1'].describe()
Out[10]:
In [11]:
data.drop(['l_r_balance','heartrate','leg_range_log_left','leg_range_log_right'], axis=1).corr(method='pearson').style.background_gradient(cmap='bwr').set_precision(2)
Out[11]:
In [12]:
yscale = alt.Scale(domain=(35, 65))
points_left = alt.Chart(data.loc['lap1'], width=650, height=100).mark_circle(opacity=0.3, color='red').encode(
alt.X('elapsed_time',
scale=alt.Scale(domain=[0, 3250]),
axis=alt.Axis(title='')
),
alt.Y('foot_range_log_left',
scale=yscale,
axis=alt.Axis(title='Lap 1'),
),
).properties(title='Foot Angular Range (Left in Red, Right in Blue)')
points_right = alt.Chart(data.loc['lap1'], width=650, height=100).mark_circle(opacity=0.3, color='blue').encode(
alt.X('elapsed_time',
scale=alt.Scale(domain=[0, 3250])),
alt.Y('foot_range_log_right', scale=yscale),
)
hist_left = alt.Chart(data.loc['lap1'], height=100).mark_area(clip=True, opacity=.3, interpolate='step', color='red').encode(
alt.Y('foot_range_log_left:Q',
bin=alt.Bin(maxbins=60, extent=yscale.domain),
stack=None,
axis=alt.Axis(title=''),
scale=alt.Scale(domain=[40,60])
),
alt.X('count()', stack=None, scale=alt.Scale(domain=[0, 100]), axis=alt.Axis(title='')
),
).properties(width=150)
hist_right = alt.Chart(data.loc['lap1'], height=100).mark_area(clip=True, opacity=.3, interpolate='step', color='blue').encode(
alt.Y('foot_range_log_right:Q',
bin=alt.Bin(maxbins=60, extent=yscale.domain),
stack=None,
axis=alt.Axis(title=''),
scale=alt.Scale(domain=[40,60])
),
alt.X('count()', stack=None, scale=alt.Scale(domain=[0, 100])),
).properties(width=150)
hist_left_rule = alt.Chart(data.loc['lap1']).mark_rule(color='red').encode(
y='mean(foot_range_log_left):Q',
size=alt.value(2)
)
hist_right_rule = alt.Chart(data.loc['lap1']).mark_rule(color='blue').encode(
y='mean(foot_range_log_right):Q',
size=alt.value(2)
)
lap1 = ((points_left + points_right) | (hist_left + hist_right + hist_left_rule + hist_right_rule))
In [13]:
yscale = alt.Scale(domain=(35, 65))
points_left = alt.Chart(data.loc['lap2'], width=650, height=100).mark_circle(opacity=0.3, color='red').encode(
alt.X('elapsed_time',
scale=alt.Scale(domain=[0, 3250]),
axis=alt.Axis(title=''),
),
alt.Y('foot_range_log_left',
scale=yscale,
axis=alt.Axis(title='Lap 2'),
),
)
points_right = alt.Chart(data.loc['lap2'], width=650, height=100).mark_circle(opacity=0.3, color='blue').encode(
alt.X('elapsed_time',
scale=alt.Scale(domain=[0, 3250]),
axis=alt.Axis(title='')
),
alt.Y('foot_range_log_right', scale=yscale),
)
hist_left = alt.Chart(data.loc['lap2'], height=100).mark_area(clip=True, opacity=.3, interpolate='step', color='red').encode(
alt.Y('foot_range_log_left:Q',
bin=alt.Bin(maxbins=60, extent=yscale.domain),
stack=None,
axis=alt.Axis(title=''),
scale=alt.Scale(domain=[40,60])
),
alt.X('count()', stack=None, scale=alt.Scale(domain=[0, 100]), axis=alt.Axis(title='')
),
).properties(width=150)
hist_right = alt.Chart(data.loc['lap2'], height=100).mark_area(clip=True, opacity=.3, interpolate='step', color='blue').encode(
alt.Y('foot_range_log_right:Q',
bin=alt.Bin(maxbins=60, extent=yscale.domain),
stack=None,
axis=alt.Axis(title=''),
scale=alt.Scale(domain=[40,60])
),
alt.X('count()', stack=None, scale=alt.Scale(domain=[0, 100])),
).properties(width=150)
hist_left_rule = alt.Chart(data.loc['lap2']).mark_rule(color='red').encode(
y='mean(foot_range_log_left):Q',
size=alt.value(2)
)
hist_right_rule = alt.Chart(data.loc['lap2']).mark_rule(color='blue').encode(
y='mean(foot_range_log_right):Q',
size=alt.value(2)
)
lap2 = ((points_left + points_right) | (hist_left + hist_right + hist_left_rule + hist_right_rule))
In [14]:
yscale = alt.Scale(domain=(35, 65))
points_left = alt.Chart(data.loc['lap3'], width=650, height=100).mark_circle(opacity=0.3, color='red').encode(
alt.X('elapsed_time',
scale=alt.Scale(domain=[0, 3250]),
axis=alt.Axis(title='Elapsed Time (s)'),
),
alt.Y('foot_range_log_left',
scale=yscale,
axis=alt.Axis(title='Lap 3'),
),
)
points_right = alt.Chart(data.loc['lap3'], width=650, height=100).mark_circle(opacity=0.3, color='blue').encode(
alt.X('elapsed_time',
scale=alt.Scale(domain=[0, 3250])),
alt.Y('foot_range_log_right', scale=yscale),
)
hist_left = alt.Chart(data.loc['lap3']).mark_area(clip=True, opacity=.3, interpolate='step', color='red').encode(
alt.Y('foot_range_log_left:Q',
bin=alt.Bin(maxbins=60, extent=yscale.domain),
stack=None,
axis=alt.Axis(title=''),
scale=alt.Scale(domain=[40,60])
),
alt.X('count()', stack=None, scale=alt.Scale(domain=[0, 100])),
).properties(width=150)
hist_right = alt.Chart(data.loc['lap3']).mark_area(clip=True, opacity=.3, interpolate='step', color='blue').encode(
alt.Y('foot_range_log_right:Q',
bin=alt.Bin(maxbins=60, extent=yscale.domain),
stack=None,
axis=alt.Axis(title=''),
scale=alt.Scale(domain=[40,60])
),
alt.X('count()', stack=None, scale=alt.Scale(domain=[0, 100])),
).properties(width=150)
hist_left_rule = alt.Chart(data.loc['lap3'], height=100).mark_rule(color='red').encode(
y='mean(foot_range_log_left):Q',
size=alt.value(2)
)
hist_right_rule = alt.Chart(data.loc['lap3'], height=100).mark_rule(color='blue').encode(
y='mean(foot_range_log_right):Q',
size=alt.value(2)
)
lap3 = ((points_left + points_right) | (hist_left + hist_right + hist_left_rule + hist_right_rule))
In [15]:
(lap1 & lap2 & lap3)
Out[15]:
In [16]:
yscale = alt.Scale(domain=(0, 40))
DSS1points_left = alt.Chart(data.loc['lap1'], width=650, height=100).mark_circle(opacity=0.3, color='red').encode(
alt.X('elapsed_time',
scale=alt.Scale(domain=[0, 3250]),
axis=alt.Axis(title='')
),
alt.Y('ankling_log_left',
scale=yscale,
axis=alt.Axis(title='Lap 1'),
),
).properties(title='DSS')
DSS1points_right = alt.Chart(data.loc['lap1'], width=650, height=100).mark_circle(opacity=0.3, color='blue').encode(
alt.X('elapsed_time',
scale=alt.Scale(domain=[0, 3250])),
alt.Y('ankling_log_right', scale=yscale),
)
DSS1hist_left = alt.Chart(data.loc['lap1'], height=100).mark_area(clip=True, opacity=.3, interpolate='step', color='red').encode(
alt.Y('ankling_log_left:Q',
bin=alt.Bin(maxbins=30, extent=yscale.domain),
stack=None,
axis=alt.Axis(title=''),
scale=alt.Scale(domain=[0,40])
),
alt.X('count()', stack=None, scale=alt.Scale(domain=[0, 30]), axis=alt.Axis(title='')
),
).properties(width=150)
DSS1hist_right = alt.Chart(data.loc['lap1'], height=100).mark_area(clip=True, opacity=.3, interpolate='step', color='blue').encode(
alt.Y('ankling_log_right:Q',
bin=alt.Bin(maxbins=30, extent=yscale.domain),
stack=None,
axis=alt.Axis(title=''),
scale=alt.Scale(domain=[0,40])
),
alt.X('count()', stack=None, scale=alt.Scale(domain=[0, 30])),
).properties(width=150)
DSS1hist_left_rule = alt.Chart(data.loc['lap1']).mark_rule(color='red').encode(
y='mean(ankling_log_left):Q',
size=alt.value(2)
)
DSS1hist_right_rule = alt.Chart(data.loc['lap1']).mark_rule(color='blue').encode(
y='mean(ankling_log_right):Q',
size=alt.value(2)
)
DSSlap1 = ((DSS1points_left + DSS1points_right) | (DSS1hist_left + DSS1hist_right + DSS1hist_left_rule + DSS1hist_right_rule))
In [17]:
yscale = alt.Scale(domain=(0, 40))
DSS2points_left = alt.Chart(data.loc['lap2'], width=650, height=100).mark_circle(opacity=0.3, color='red').encode(
alt.X('elapsed_time',
scale=alt.Scale(domain=[0, 3250]),
axis=alt.Axis(title='')
),
alt.Y('ankling_log_left',
scale=yscale,
axis=alt.Axis(title='Lap 2'),
),
)
DSS2points_right = alt.Chart(data.loc['lap2'], width=650, height=100).mark_circle(opacity=0.3, color='blue').encode(
alt.X('elapsed_time',
scale=alt.Scale(domain=[0, 3250])),
alt.Y('ankling_log_right', scale=yscale),
)
DSS2hist_left = alt.Chart(data.loc['lap2'], height=100).mark_area(clip=True, opacity=.3, interpolate='step', color='red').encode(
alt.Y('ankling_log_left:Q',
bin=alt.Bin(maxbins=30, extent=yscale.domain),
stack=None,
axis=alt.Axis(title=''),
scale=alt.Scale(domain=[0,40])
),
alt.X('count()', stack=None, scale=alt.Scale(domain=[0, 30]), axis=alt.Axis(title='')
),
).properties(width=150)
DSS2hist_right = alt.Chart(data.loc['lap2'], height=100).mark_area(clip=True, opacity=.3, interpolate='step', color='blue').encode(
alt.Y('ankling_log_right:Q',
bin=alt.Bin(maxbins=30, extent=yscale.domain),
stack=None,
axis=alt.Axis(title=''),
scale=alt.Scale(domain=[0,40])
),
alt.X('count()', stack=None, scale=alt.Scale(domain=[0, 30])),
).properties(width=150)
DSS2hist_left_rule = alt.Chart(data.loc['lap2']).mark_rule(color='red').encode(
y='mean(ankling_log_left):Q',
size=alt.value(2)
)
DSS2hist_right_rule = alt.Chart(data.loc['lap2']).mark_rule(color='blue').encode(
y='mean(ankling_log_right):Q',
size=alt.value(2)
)
DSSlap2 = ((DSS2points_left + DSS2points_right) | (DSS2hist_left + DSS2hist_right + DSS2hist_left_rule + DSS2hist_right_rule))
In [18]:
yscale = alt.Scale(domain=(0, 40))
DSS3points_left = alt.Chart(data.loc['lap3'], width=650, height=100).mark_circle(opacity=0.3, color='red').encode(
alt.X('elapsed_time',
scale=alt.Scale(domain=[0, 3250]),
axis=alt.Axis(title='')
),
alt.Y('ankling_log_left',
scale=yscale,
axis=alt.Axis(title='Lap 3'),
),
)
DSS3points_right = alt.Chart(data.loc['lap3'], width=650, height=100).mark_circle(opacity=0.3, color='blue').encode(
alt.X('elapsed_time',
scale=alt.Scale(domain=[0, 3250])),
alt.Y('ankling_log_right', scale=yscale),
)
DSS3hist_left = alt.Chart(data.loc['lap3'], height=100).mark_area(clip=True, opacity=.3, interpolate='step', color='red').encode(
alt.Y('ankling_log_left:Q',
bin=alt.Bin(maxbins=30, extent=yscale.domain),
stack=None,
axis=alt.Axis(title=''),
scale=alt.Scale(domain=[0,40])
),
alt.X('count()', stack=None, scale=alt.Scale(domain=[0, 30]), axis=alt.Axis(title='')
),
).properties(width=150)
DSS3hist_right = alt.Chart(data.loc['lap3'], height=100).mark_area(clip=True, opacity=.3, interpolate='step', color='blue').encode(
alt.Y('ankling_log_right:Q',
bin=alt.Bin(maxbins=30, extent=yscale.domain),
stack=None,
axis=alt.Axis(title=''),
scale=alt.Scale(domain=[0,40])
),
alt.X('count()', stack=None, scale=alt.Scale(domain=[0, 30])),
).properties(width=150)
DSS3hist_left_rule = alt.Chart(data.loc['lap3']).mark_rule(color='red').encode(
y='mean(ankling_log_left):Q',
size=alt.value(2)
)
DSS3hist_right_rule = alt.Chart(data.loc['lap3']).mark_rule(color='blue').encode(
y='mean(ankling_log_right):Q',
size=alt.value(2)
)
DSSlap3 = ((DSS3points_left + DSS3points_right) | (DSS3hist_left + DSS3hist_right + DSS3hist_left_rule + DSS3hist_right_rule))
In [19]:
(DSSlap1 & DSSlap2 & DSSlap3)
Out[19]:
In [20]:
lap = [1, 2, 3]
yleft = [data.loc['lap1']['ankling_log_left'].mean(), data.loc['lap2']['ankling_log_left'].mean(), data.loc['lap3']['ankling_log_left'].mean()]
yright = [data.loc['lap1']['ankling_log_right'].mean(), data.loc['lap2']['ankling_log_right'].mean(), data.loc['lap3']['ankling_log_right'].mean()]
# set up data frame
meandata = pd.DataFrame({'lap':lap, 'yleft':yleft, 'yright':yright})
# generate the points
pointsleft = alt.Chart(meandata).mark_line().encode(
alt.X('lap:Q',
scale=alt.Scale(domain=(0,4)),
axis=alt.Axis(title='lap')
),
alt.Y('yleft',
scale=alt.Scale(zero=False, domain=(0.5, 1)),
axis=alt.Axis(title='mean DSS')
),
color=alt.value('red')
)
# generate the point
pointsright = alt.Chart(meandata).mark_line().encode(
alt.X('lap:Q',
scale=alt.Scale(domain=(0,4)),
axis=alt.Axis(title='lap')
),
alt.Y('yright',
scale=alt.Scale(zero=False, domain=(0.5, 1)),
),
color=alt.value('blue')
).properties(title='mean DSS for left (red) and right (blue)')
(pointsleft + pointsright)
Out[20]:
In [21]:
altitude = alt.Chart(data.loc['lap3'], width=900).mark_area(color='lightgrey').encode(
alt.X('elapsed_time',
axis=alt.Axis(title='Elapsed Time (s)'),
),
alt.Y('altitude',
scale=alt.Scale(domain=[0, 200]),
axis=alt.Axis(title='', ticks=False, labels=False, grid=False)
),
)
power = alt.Chart(data.loc['lap3'], width=900).mark_line().encode(
alt.X('elapsed_time',
axis=alt.Axis(title='Elapsed Time (s)'),
),
alt.Y('power',
scale=alt.Scale(domain=[0, 500]),
axis=alt.Axis(title='', ticks=False, labels=False, grid=False)
),
color=alt.value('red')
)
cadence = alt.Chart(data.loc['lap3'], width=900).mark_line().encode(
alt.X('elapsed_time',
axis=alt.Axis(title='Elapsed Time (s)'),
),
alt.Y('cadence',
scale=alt.Scale(domain=[60, 120]),
axis=alt.Axis(title='', ticks=False, labels=False, grid=False)
),
color=alt.value('lightblue')
)
speed = alt.Chart(data.loc['lap3'], width=900).mark_line().encode(
alt.X('elapsed_time',
axis=alt.Axis(title='Elapsed Time (s)'),
),
alt.Y('speed',
scale=alt.Scale(domain=[0, 20]),
axis=alt.Axis(title='', ticks=False, labels=False, grid=False)
),
color=alt.value('green')
)
# Create a selection that chooses the nearest point & selects based on x-value
nearest = alt.selection(type='single', nearest=True, on='mouseover',
fields=['elapsed_time'], empty='none')
# Transparent selectors across the chart. This is what tells us
# the x-value of the cursor
selectors = altitude.mark_point().encode(
x='elapsed_time',
opacity=alt.value(0),
).add_selection(
nearest
)
# Draw points on the line, and highlight based on selection
speedpoints = speed.mark_point().encode(
opacity=alt.condition(nearest, alt.value(1), alt.value(0))
)
cadencepoints = cadence.mark_point().encode(
opacity=alt.condition(nearest, alt.value(1), alt.value(0))
)
powerpoints = power.mark_point().encode(
opacity=alt.condition(nearest, alt.value(1), alt.value(0))
)
# Draw text labels near the points, and highlight based on selection
speedtext = speed.mark_text(align='left', dx=5, dy=-5, fontSize=14, fontWeight='bold').encode(
text=alt.condition(nearest, 'speed', alt.value(' '))
)
cadencetext = cadence.mark_text(align='left', dx=5, dy=-5, fontSize=14, fontWeight='bold').encode(
text=alt.condition(nearest,'cadence', alt.value(' '))
)
powertext = power.mark_text(align='left', dx=5, dy=-5, fontSize=14, fontWeight='bold').encode(
text=alt.condition(nearest,'power', alt.value(' '))
)
# Draw a rule at the location of the selection
rules = altitude.mark_rule(color='grey').encode(
x='elapsed_time',
).transform_filter(
nearest
)
alt.layer(
altitude,
power,
cadence,
speed,
selectors,
powerpoints,
cadencepoints,
speedpoints,
powertext,
cadencetext,
speedtext,
rules,
data=data.loc['lap3']
).resolve_scale(
y='independent'
).interactive(bind_y=False)
Out[21]:
In [22]:
altitude1 = alt.Chart(data.loc['lap1'], width=900).mark_area(color='lightgrey').encode(
alt.X('elapsed_time',
axis=alt.Axis(title='Elapsed time (s)'),
),
alt.Y('altitude',
scale=alt.Scale(domain=[0, 150]),
axis=alt.Axis(title='Altitude (m)', ticks=False, labels=False, grid=False)
),
)
altitude2 = alt.Chart(data.loc['lap2'], width=900).mark_area(color='lightgrey').encode(
alt.X('elapsed_time',
# axis=alt.Axis(title='Elapsed lap time (s)'),
),
alt.Y('altitude',
scale=alt.Scale(domain=[0, 150]),
axis=alt.Axis(title='', ticks=False, labels=False, grid=False)
),
)
altitude3 = alt.Chart(data.loc['lap3'], width=900).mark_area(color='lightgrey').encode(
alt.X('elapsed_time',
# axis=alt.Axis(title='Elapsed lap time (s)'),
),
alt.Y('altitude',
scale=alt.Scale(domain=[0, 150]),
axis=alt.Axis(title='', ticks=False, labels=False, grid=False)
),
)
speed1 = alt.Chart(data.loc['lap1'], width=900).mark_line().encode(
alt.X('elapsed_time',
),
alt.Y('speed',
scale=alt.Scale(domain=[0, 18]),
axis=alt.Axis(title='Speed (m/s)')
),
color=alt.value('green')
)
speed2 = alt.Chart(data.loc['lap2'], width=900).mark_line().encode(
alt.X('elapsed_time',
# axis=alt.Axis(title='Elapsed Time (s)'),
),
alt.Y('speed',
scale=alt.Scale(domain=[0, 18]),
axis=alt.Axis(title='', ticks=False, labels=False, grid=False)
),
color=alt.value('orange')
)
speed3 = alt.Chart(data.loc['lap3'], width=900).mark_line().encode(
alt.X('elapsed_time',
# axis=alt.Axis(title='Elapsed Time (s)'),
),
alt.Y('speed',
scale=alt.Scale(domain=[0, 18]),
axis=alt.Axis(title='', ticks=False, labels=False, grid=False)
),
color=alt.value('blue')
)
# Create a selection that chooses the nearest point & selects based on x-value
nearest = alt.selection(type='single', nearest=True, on='mouseover',
fields=['elapsed_time'], empty='none')
# Transparent selectors across the chart. This is what tells us
# the x-value of the cursor
selectors = altitude.mark_point().encode(
x='elapsed_time',
opacity=alt.value(0),
).add_selection(
nearest
)
# Draw points on the line, and highlight based on selection
speedpoints1 = speed1.mark_point().encode(
opacity=alt.condition(nearest, alt.value(1), alt.value(0))
)
speedpoints2 = speed2.mark_point().encode(
opacity=alt.condition(nearest, alt.value(1), alt.value(0))
)
speedpoints3 = speed3.mark_point().encode(
opacity=alt.condition(nearest, alt.value(1), alt.value(0))
)
# Draw text labels near the points, and highlight based on selection
speedtext1 = speed1.mark_text(align='left', dx=5, dy=-5, fontSize=12, fontWeight='bold').encode(
text=alt.condition(nearest, 'speed', alt.value(' '))
)
speedtext2 = speed2.mark_text(align='left', dx=5, dy=-5, fontSize=12, fontWeight='bold').encode(
text=alt.condition(nearest, 'speed', alt.value(' '))
)
speedtext3 = speed3.mark_text(align='left', dx=5, dy=-5, fontSize=12, fontWeight='bold').encode(
text=alt.condition(nearest, 'speed', alt.value(' '))
)
# Draw a rule at the location of the selection
rules = altitude.mark_rule(color='grey').encode(
x='elapsed_time',
).transform_filter(
nearest
)
alt.layer(
altitude1,
altitude2,
altitude3,
speed1,
speed2,
speed3,
# selectors,
# speedpoints1,
# speedpoints2,
# speedpoints3,
# speedtext1,
# speedtext2,
# speedtext3,
# rules,
# data=data.loc['lap1']
).resolve_scale(
y='independent'
).interactive(bind_y=False)
Out[22]:
In [23]:
altitude = alt.Chart(data.loc['lap1'].reset_index(), width=900).mark_area(color='lightgrey').encode(
alt.X('index',
axis=alt.Axis(title='Elapsed lap time (s)'),
),
alt.Y('altitude',
scale=alt.Scale(domain=[0, 150]),
axis=alt.Axis(title='Altitude (m)')
),
)
torso1 = alt.Chart(data.loc['lap1'].reset_index(), width=900).mark_line().encode(
alt.X('index',
),
alt.Y('torso_angle_log_center',
scale=alt.Scale(domain=[0, 40]),
# axis=alt.Axis(title='Torso Angle (deg)')
),
color=alt.value('yellow')
)
torso2 = alt.Chart(data.loc['lap2'].reset_index(), width=900).mark_line().encode(
alt.X('index',
),
alt.Y('torso_angle_log_center',
scale=alt.Scale(domain=[0, 40]),
),
color=alt.value('orange')
)
torso3 = alt.Chart(data.loc['lap3'].reset_index(), width=900).mark_line().encode(
alt.X('index',
),
alt.Y('torso_angle_log_center',
scale=alt.Scale(domain=[0, 40]),
),
color=alt.value('red')
)
alt.layer(
altitude,
torso1,
torso2,
torso3
).resolve_scale(
y='independent'
).interactive(bind_y=False)
Out[23]:
In [24]:
xtitle='FAR Left for Q1'
ytitle='FAR Right for Q1'
xscl=[0,55]
yscl=[0,55]
farq11 = alt.Chart(data.loc['lap1'], height=300, width=300).mark_rect().encode(
alt.X('pedaling_delay_log_left:Q',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=xscl),
axis=alt.Axis(title=xtitle)
),
alt.Y('pedaling_delay_log_right:Q',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=xscl),
axis=alt.Axis(title=ytitle)
),
alt.Color('power:Q', scale=alt.Scale(domain=[0, 600], scheme='greenblue'))
).properties(title='Lap 1')
farq12 = alt.Chart(data.loc['lap2'], height=300, width=300).mark_rect().encode(
alt.X('pedaling_delay_log_left:Q',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=xscl),
axis=alt.Axis(title=xtitle)
),
alt.Y('pedaling_delay_log_right:Q',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=yscl),
axis=alt.Axis(title=ytitle)
),
alt.Color('power:Q', scale=alt.Scale(domain=[0, 600], scheme='greenblue'))
).properties(title='Lap 2')
farq13 = alt.Chart(data.loc['lap3'], height=300, width=300).mark_rect().encode(
alt.X('pedaling_delay_log_left:Q',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=xscl),
axis=alt.Axis(title=xtitle)
),
alt.Y('pedaling_delay_log_right:Q',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=yscl),
axis=alt.Axis(title=ytitle)
),
alt.Color('power:Q', scale=alt.Scale(domain=[0, 600], scheme='greenblue'))
).properties(title='Lap 3')
farq11xmean = alt.Chart(data.loc['lap1']).mark_rule(color='red').encode(
x='mean(pedaling_delay_log_left):Q',
size=alt.value(1)
)
farq11ymean = alt.Chart(data.loc['lap1']).mark_rule(color='red').encode(
y='mean(pedaling_delay_log_right):Q',
size=alt.value(1)
)
farq12xmean = alt.Chart(data.loc['lap2']).mark_rule(color='red').encode(
x='mean(pedaling_delay_log_left):Q',
size=alt.value(1)
)
farq12ymean = alt.Chart(data.loc['lap2']).mark_rule(color='red').encode(
y='mean(pedaling_delay_log_right):Q',
size=alt.value(1)
)
farq13xmean = alt.Chart(data.loc['lap3']).mark_rule(color='red').encode(
x='mean(pedaling_delay_log_left):Q',
size=alt.value(1)
)
farq13ymean = alt.Chart(data.loc['lap3']).mark_rule(color='red').encode(
y='mean(pedaling_delay_log_right):Q',
size=alt.value(1)
)
(farq11 + farq11xmean + farq11ymean) | (farq12 + farq12xmean + farq12ymean) | (farq13 + farq13xmean + farq13ymean)
Out[24]:
In [25]:
mb=100
xtitle='FAR Left'
ytitle='FAR right'
foot1 = alt.Chart(data.loc['lap1'], height=300, width=300).mark_rect().encode(
alt.X('foot_range_log_left',
bin=alt.Bin(maxbins=mb),
scale=alt.Scale(domain=[30, 70]),
axis=alt.Axis(title=xtitle)
),
alt.Y('foot_range_log_right',
bin=alt.Bin(maxbins=mb),
scale=alt.Scale(domain=[30, 70]),
axis=alt.Axis(title=ytitle)
),
alt.Color('power:Q', scale=alt.Scale(domain=[0, 600], scheme='greenblue'))
).properties(title='Lap 1')
foot2 = alt.Chart(data.loc['lap2'], height=300, width=300).mark_rect().encode(
alt.X('foot_range_log_left',
bin=alt.Bin(maxbins=mb),
scale=alt.Scale(domain=[30, 70]),
axis=alt.Axis(title=xtitle)
),
alt.Y('foot_range_log_right',
bin=alt.Bin(maxbins=mb),
scale=alt.Scale(domain=[30, 70]),
axis=alt.Axis(title=ytitle)
),
alt.Color('power:Q', scale=alt.Scale(domain=[0, 600], scheme='greenblue'))
).properties(title='Lap 2')
foot3 = alt.Chart(data.loc['lap3'], height=300, width=300).mark_rect().encode(
alt.X('foot_range_log_left',
bin=alt.Bin(maxbins=mb),
scale=alt.Scale(domain=[30, 70]),
axis=alt.Axis(title=xtitle)
),
alt.Y('foot_range_log_right',
bin=alt.Bin(maxbins=mb),
scale=alt.Scale(domain=[30, 70]),
axis=alt.Axis(title=ytitle)
),
alt.Color('power:Q', scale=alt.Scale(domain=[0, 600], scheme='greenblue'))
).properties(title='Lap 3')
foot1xmean = alt.Chart(data.loc['lap1']).mark_rule(color='red').encode(
x='mean(foot_range_log_left):Q',
size=alt.value(1)
)
foot1ymean = alt.Chart(data.loc['lap1']).mark_rule(color='red').encode(
y='mean(foot_range_log_right):Q',
size=alt.value(1)
)
foot2xmean = alt.Chart(data.loc['lap2']).mark_rule(color='red').encode(
x='mean(foot_range_log_left):Q',
size=alt.value(1)
)
foot2ymean = alt.Chart(data.loc['lap2']).mark_rule(color='red').encode(
y='mean(foot_range_log_right):Q',
size=alt.value(1)
)
foot3xmean = alt.Chart(data.loc['lap3']).mark_rule(color='red').encode(
x='mean(foot_range_log_left):Q',
size=alt.value(1)
)
foot3ymean = alt.Chart(data.loc['lap3']).mark_rule(color='red').encode(
y='mean(foot_range_log_right):Q',
size=alt.value(1)
)
(foot1 + foot1xmean + foot1ymean) | (foot2 + foot2xmean + foot2ymean) | (foot3 + foot3xmean + foot3ymean)
Out[25]:
In [26]:
yscl=[3, 37]
xscl=[38, 67]
xtitle='Pelvic Angle'
ytitle='Torso Angle'
ang1=alt.Chart(data.loc['lap1'], height=300, width=300).mark_rect().encode(
alt.X('waist_angle_log_center:Q',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=xscl),
axis=alt.Axis(title=xtitle)
),
alt.Y('torso_angle_log_center:Q',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=yscl),
axis=alt.Axis(title=ytitle)
),
alt.Color('power:Q', scale=alt.Scale(domain=[0, 600], scheme='greenblue'))
).properties(title='Lap 1')
ang2=alt.Chart(data.loc['lap2'], height=300, width=300).mark_rect().encode(
alt.X('waist_angle_log_center:Q',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=xscl),
axis=alt.Axis(title=xtitle)
),
alt.Y('torso_angle_log_center:Q',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=yscl),
axis=alt.Axis(title=ytitle)
),
alt.Color('power:Q', scale=alt.Scale(domain=[0, 600], scheme='greenblue'))
).properties(title='Lap 2')
ang3=alt.Chart(data.loc['lap3'], height=300, width=300).mark_rect().encode(
alt.X('waist_angle_log_center:Q',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=xscl),
axis=alt.Axis(title=xtitle)
),
alt.Y('torso_angle_log_center:Q',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=yscl),
axis=alt.Axis(title=ytitle)
),
alt.Color('power:Q', scale=alt.Scale(domain=[0, 600], scheme='greenblue'))
).properties(title='Lap 3')
ang1xmean = alt.Chart(data.loc['lap1']).mark_rule(color='red').encode(
x='mean(waist_angle_log_center):Q',
size=alt.value(1)
)
ang1ymean = alt.Chart(data.loc['lap1']).mark_rule(color='red').encode(
y='mean(torso_angle_log_center):Q',
size=alt.value(1)
)
ang2xmean = alt.Chart(data.loc['lap2']).mark_rule(color='red').encode(
x='mean(waist_angle_log_center):Q',
size=alt.value(1)
)
ang2ymean = alt.Chart(data.loc['lap2']).mark_rule(color='red').encode(
y='mean(torso_angle_log_center):Q',
size=alt.value(1)
)
ang3xmean = alt.Chart(data.loc['lap3']).mark_rule(color='red').encode(
x='mean(waist_angle_log_center):Q',
size=alt.value(1)
)
ang3ymean = alt.Chart(data.loc['lap3']).mark_rule(color='red').encode(
y='mean(torso_angle_log_center):Q',
size=alt.value(1)
)
(ang1 + ang1xmean + ang1ymean) | (ang2 + ang2xmean + ang2ymean) | (ang3 + ang3xmean + ang3ymean)
Out[26]:
In [28]:
f, (ax1, ax2, ax3) = plt.subplots(1, 3)
sns.violinplot(y=data.loc['lap1']['waist_angle_log_center'], ax=ax1, scale="count", inner="quartile", color="red").set_title("Lap 1")
sns.violinplot(y=data.loc['lap2']['waist_angle_log_center'], ax=ax2, scale="count", inner="quartile", color="skyblue").set_title("Lap 2")
sns.violinplot(y=data.loc['lap3']['waist_angle_log_center'], ax=ax3, scale="count", inner="quartile", color="lightgreen").set_title("Lap 3")
plt.tight_layout()
In [29]:
f, (ax1, ax2, ax3) = plt.subplots(1, 3)
sns.violinplot(y=data.loc['lap1']['torso_angle_log_center'], ax=ax1, scale="count", inner="quartile", color="red").set_title("Lap 1")
sns.violinplot(y=data.loc['lap2']['torso_angle_log_center'], ax=ax2, scale="count", inner="quartile", color="skyblue").set_title("Lap 2")
sns.violinplot(y=data.loc['lap3']['torso_angle_log_center'], ax=ax3, scale="count", inner="quartile", color="lightgreen").set_title("Lap 3")
plt.tight_layout()
In [30]:
xscl=[0, 35]
yscl=[0, 20]
xtitle='Pelvic Rotation'
ytitle='Torso Rotation'
rot1 = alt.Chart(data.loc['lap1'], height=300, width=300).mark_rect().encode(
alt.X('waist_d_rot_y_center',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=xscl),
axis=alt.Axis(title=xtitle)
),
alt.Y('torso_d_rot_y_center',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=yscl),
axis=alt.Axis(title=ytitle)
),
alt.Color('power:Q', scale=alt.Scale(domain=[0, 600], scheme='greenblue'))
).properties(title='Lap 1')
rot2 = alt.Chart(data.loc['lap2'], height=300, width=300).mark_rect().encode(
alt.X('waist_d_rot_y_center',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=xscl),
axis=alt.Axis(title=xtitle)
),
alt.Y('torso_d_rot_y_center',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=yscl),
axis=alt.Axis(title=ytitle)
),
alt.Color('power:Q', scale=alt.Scale(domain=[0, 600], scheme='greenblue'))
).properties(title='Lap 2')
rot3 = alt.Chart(data.loc['lap3'], height=300, width=300).mark_rect().encode(
alt.X('waist_d_rot_y_center',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=xscl),
axis=alt.Axis(title=xtitle)
),
alt.Y('torso_d_rot_y_center',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=yscl),
axis=alt.Axis(title=ytitle)
),
alt.Color('power:Q', scale=alt.Scale(domain=[0, 600], scheme='greenblue'))
).properties(title='Lap 3')
rot1xmean = alt.Chart(data.loc['lap1']).mark_rule(color='red').encode(
x='mean(waist_d_rot_y_center):Q',
size=alt.value(1)
)
rot1ymean = alt.Chart(data.loc['lap1']).mark_rule(color='red').encode(
y='mean(torso_d_rot_y_center):Q',
size=alt.value(1)
)
rot2xmean = alt.Chart(data.loc['lap2']).mark_rule(color='red').encode(
x='mean(waist_d_rot_y_center):Q',
size=alt.value(1)
)
rot2ymean = alt.Chart(data.loc['lap2']).mark_rule(color='red').encode(
y='mean(torso_d_rot_y_center):Q',
size=alt.value(1)
)
rot3xmean = alt.Chart(data.loc['lap3']).mark_rule(color='red').encode(
x='mean(waist_d_rot_y_center):Q',
size=alt.value(1)
)
rot3ymean = alt.Chart(data.loc['lap3']).mark_rule(color='red').encode(
y='mean(torso_d_rot_y_center):Q',
size=alt.value(1)
)
(rot1 + rot1xmean + rot1ymean) | (rot2 + rot2xmean + rot2ymean) | (rot3 + rot3xmean + rot3ymean)
Out[30]:
In [31]:
xscl=[0, 20]
yscl=[0, 20]
xtitle='Pelvic Rock'
ytitle='Torso Rock'
roc1 = alt.Chart(data.loc['lap1'], height=300, width=300).mark_rect().encode(
alt.X('waist_d_rot_z_center',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=xscl),
axis=alt.Axis(title=xtitle)
),
alt.Y('torso_d_rot_z_center',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=yscl),
axis=alt.Axis(title=ytitle)
),
alt.Color('power:Q', scale=alt.Scale(domain=[0, 600], scheme='greenblue'))
).properties(title='Lap 1')
roc2 = alt.Chart(data.loc['lap2'], height=300, width=300).mark_rect().encode(
alt.X('waist_d_rot_z_center',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=xscl),
axis=alt.Axis(title=xtitle)
),
alt.Y('torso_d_rot_z_center',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=yscl),
axis=alt.Axis(title=ytitle)
),
alt.Color('power:Q', scale=alt.Scale(domain=[0, 600], scheme='greenblue'))
).properties(title='Lap 2')
roc3 = alt.Chart(data.loc['lap3'], height=300, width=300).mark_rect().encode(
alt.X('waist_d_rot_z_center',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=xscl),
axis=alt.Axis(title=xtitle)
),
alt.Y('torso_d_rot_z_center',
bin=alt.Bin(maxbins=40),
scale=alt.Scale(domain=yscl),
axis=alt.Axis(title=ytitle)
),
alt.Color('power:Q', scale=alt.Scale(domain=[0, 600], scheme='greenblue'))
).properties(title='Lap 3')
roc1xmean = alt.Chart(data.loc['lap1']).mark_rule(color='red').encode(
x='mean(waist_d_rot_z_center):Q',
size=alt.value(1)
)
roc1ymean = alt.Chart(data.loc['lap1']).mark_rule(color='red').encode(
y='mean(torso_d_rot_z_center):Q',
size=alt.value(1)
)
roc2xmean = alt.Chart(data.loc['lap2']).mark_rule(color='red').encode(
x='mean(waist_d_rot_z_center):Q',
size=alt.value(1)
)
roc2ymean = alt.Chart(data.loc['lap2']).mark_rule(color='red').encode(
y='mean(torso_d_rot_z_center):Q',
size=alt.value(1)
)
roc3xmean = alt.Chart(data.loc['lap3']).mark_rule(color='red').encode(
x='mean(waist_d_rot_z_center):Q',
size=alt.value(1)
)
roc3ymean = alt.Chart(data.loc['lap3']).mark_rule(color='red').encode(
y='mean(torso_d_rot_z_center):Q',
size=alt.value(1)
)
(roc1 + roc1xmean + roc1ymean) | (roc2 + roc2xmean + roc2ymean) | (roc3 + roc3xmean + roc3ymean)
Out[31]: