Skip to content

Commit

Permalink
Merge pull request #553 from eitanlees/horizon-graph
Browse files Browse the repository at this point in the history
Horizon Graph Example
  • Loading branch information
jakevdp authored Mar 5, 2018
2 parents a98843e + 2c207dd commit cf4ebb6
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions altair/vegalite/v2/examples/horizon_graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Horizon Graph
-------------
This example shows how to make a Horizon Graph with 2 layers. (See https://idl.cs.washington.edu/papers/horizon/ for more details on Horizon Graphs.)
"""

import altair as alt
import pandas as pd

df = pd.DataFrame([
{"x": 1, "y": 28}, {"x": 2, "y": 55},
{"x": 3, "y": 43}, {"x": 4, "y": 91},
{"x": 5, "y": 81}, {"x": 6, "y": 53},
{"x": 7, "y": 19}, {"x": 8, "y": 87},
{"x": 9, "y": 52}, {"x": 10, "y": 48},
{"x": 11, "y": 24}, {"x": 12, "y": 49},
{"x": 13, "y": 87}, {"x": 14, "y": 66},
{"x": 15, "y": 17}, {"x": 16, "y": 27},
{"x": 17, "y": 68}, {"x": 18, "y": 16},
{"x": 19, "y": 49}, {"x": 20, "y": 15}
])

area1 = alt.Chart(df).mark_area(clip=True, interpolate='monotone').encode(
x = alt.X('x', scale=alt.Scale(zero=False, nice=False)),
y = alt.Y('y', scale=alt.Scale(domain=[0, 50]),
axis=alt.Axis(title='y')),
opacity = alt.value(0.6)
).properties(
width=300,
height=50
)
area2 = alt.Chart(df).mark_area(clip=True, interpolate='monotone').encode(
x = 'x',
y = alt.Y('ny:Q', scale=alt.Scale(domain=[0, 50])),
opacity = alt.value(0.3)
).transform_calculate("ny", "datum.y - 50")

chart = area1 + area2

0 comments on commit cf4ebb6

Please sign in to comment.