forked from vega/altair
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
Interactive chart using the input element | ||
============================ | ||
This is an example of a horizontal stacked bar chart using data which contains crop yields over different regions and different years in the 1930s. | ||
""" | ||
# category: interactive charts | ||
|
||
import altair as alt | ||
from vega_datasets import data | ||
|
||
search_input = alt.selection_point( | ||
fields=['Name'], | ||
empty=False, # Start with no points selected | ||
bind=alt.binding( | ||
input='text', # Change this to any of the options at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types | ||
placeholder="Car model", | ||
name='Search ', | ||
) | ||
) | ||
alt.Chart(data.cars.url).mark_point(size=60).encode( | ||
x='Horsepower:Q', | ||
y='Miles_per_Gallon:Q', | ||
tooltip='Name:N', | ||
opacity=alt.condition( # This condition would also need to be updated accordingly | ||
search_input, | ||
alt.value(1), | ||
alt.value(0.05) | ||
) | ||
).add_params( | ||
search_input | ||
) |