Skip to content

Commit

Permalink
Merge pull request #534 from eitanlees/layered-histogram
Browse files Browse the repository at this point in the history
Layered Histogram Example
  • Loading branch information
jakevdp authored Feb 28, 2018
2 parents eda7c0f + 9caa08f commit 73eed85
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions altair/vegalite/v2/examples/layered_histogram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Layered Histogram
=================
This example shows how to make a layered histogram in Altair.
"""

import pandas as pd
import altair as alt
import numpy as np
np.random.seed(42)

# Generating Data
df = pd.DataFrame({'Trial A':np.random.normal(0, 0.8, 1000),
'Trial B':np.random.normal(-2, 1, 1000),
'Trial C':np.random.normal(3, 2, 1000)})

# Tidying Data
df = pd.melt(df, id_vars=df.index.name,
value_vars=df.columns,
var_name = 'Experiment',
value_name='Measurement')

chart = alt.Chart(df).mark_area(opacity=0.3, interpolate='step').encode(
x=alt.X('Measurement',bin = alt.BinParams(maxbins=100)),
y=alt.Y('count(*):Q', stack=None),
color=alt.Color('Experiment',
scale=alt.Scale(range=['#0000ff',
'#008000',
'#ff0000'])
)
)

0 comments on commit 73eed85

Please sign in to comment.