Skip to content

Instantly share code, notes, and snippets.

@Ram-N
Created April 29, 2018 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ram-N/b0d50995690d830e23b3996ad0c47c2e to your computer and use it in GitHub Desktop.
Save Ram-N/b0d50995690d830e23b3996ad0c47c2e to your computer and use it in GitHub Desktop.
alarms in Altair
import pandas as pd
df = pd.DataFrame([
['2018-03-11', '11:03', 86],
['2018-03-14', '09:27', 43],
['2018-03-14', '12:08', 22],
['2018-03-15', '03:13', 140],
['2018-03-17', '18:06', 10]],
columns=['Date','Time','Duration'])
df['dt'] = pd.to_datetime(df['Date'] +' ' + df['Time'])
df['ht'] = 1
df['End'] = pd.to_datetime(df['dt']) + pd.to_timedelta(df['Duration'], unit='m')
import altair as alt
chart = alt.Chart(df).mark_bar().encode(
x=alt.X('dt'),
y=alt.Y('ht')
)
rule = alt.Chart(df).mark_rule(color='firebrick').encode(
alt.X(
'dt:T',
timeUnit='yearmonthdate',
axis=alt.Axis(format='%m/%d', title='Dates of Events')
),
alt.Y(
'ht',
scale=alt.Scale(domain=[-10, 10]),
axis=alt.Axis(title='Event')
),
alt.X2('End')
).properties(
width=700,
height=300
)
chart + rule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment