Line Chart with Custom Confidence Interval in Altair
You can layer a line and an area chart, usng the y
and y2
encodings to specify the range:
import altair as altimport pandas as pdimport numpy as npx = np.random.normal(100,5,100)epsilon = 10data = pd.DataFrame({ 'x': x, 'lower': x - epsilon, 'upper': x + epsilon}).reset_index()line = alt.Chart(data).mark_line().encode( x='index', y='x')band = alt.Chart(data).mark_area( opacity=0.5).encode( x='index', y='lower', y2='upper')band + line