Created
January 18, 2020 01:37
-
-
Save hamelsmu/af8af83ca6838448a0dc0236629b277e to your computer and use it in GitHub Desktop.
How to make vertical line in altair
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from vega_datasets import data as vega_data | |
import pandas as pd | |
import altair as alt | |
data = pd.read_json(vega_data.gapminder.url) | |
data2000 = data.loc[data['year'] == 2000] | |
chart1 = alt.Chart(data2000).mark_line().encode( | |
alt.X('fertility:Q'), | |
alt.Y('life_expect:Q')) | |
### fake points for vertical line ### | |
vertical_line = alt.Data(values=[{'y_start':0, | |
'y_end':60, | |
'x_pos':6}]) | |
chart2 = alt.Chart(vertical_line).mark_line().encode( | |
alt.Y('y_start:Q'), | |
alt.Y2('y_end:Q'), | |
alt.X('x_pos:Q')) | |
chart1 + chart2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
will produce a chart that looks like this
cc: @dansbecker