Skip to content

Instantly share code, notes, and snippets.

@BindiChen
Last active May 1, 2020 15:40
Show Gist options
  • Save BindiChen/0dea2e7fa189f8ff1397180f3b764cc7 to your computer and use it in GitHub Desktop.
Save BindiChen/0dea2e7fa189f8ff1397180f3b764cc7 to your computer and use it in GitHub Desktop.
An interactive Data Visualization chart using Altair
import altair as alt
from vega_datasets import data
cars = data.cars()
brush = alt.selection_interval()
points = alt.Chart(cars).mark_point().encode(
x='Horsepower:Q',
y='Miles_per_Gallon:Q',
color=alt.condition(brush, 'Origin:N', alt.value('lightgray'))
).add_selection(
brush
)
bars = alt.Chart(cars).mark_bar().encode(
y='Origin:N',
color='Origin:N',
x='count(Origin):Q'
).transform_filter(
brush
)
points & bars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment