Interactive Charts With Altair

Charts made with Altair remain interactive. Example charts taken from this repo, specifically this notebook.

Example 1: DropDown

# single-value selection over [Major_Genre, MPAA_Rating] pairs
# use specific hard-wired values as the initial selected values
selection = alt.selection_single(
    fields=['Major_Genre', 'MPAA_Rating'],
    init={'Major_Genre': 'Drama', 'MPAA_Rating': 'R'},
    bind={'Major_Genre': alt.binding_select(options=genres), 'MPAA_Rating': alt.binding_radio(options=mpaa)}
# scatter plot, modify opacity based on selection
    opacity=alt.condition(selection, alt.value(0.75), alt.value(0.05))

Example 2: Tooltips

    alt.selection_interval(bind='scales', encodings=['x'])
    y=alt.Y('IMDB_Rating:Q', axis=alt.Axis(minExtent=30)), # use min extent to stabilize axis title placement
    tooltip=['Title:N', 'Release_Date:N', 'IMDB_Rating:Q', 'Rotten_Tomatoes_Rating:Q']

Example 3: More Tooltips

# select a point for which to provide details-on-demand
label = alt.selection_single(
    encodings=['x'], # limit selection to x-axis value
    on='mouseover',  # select on mouseover events
    nearest=True,    # select data point nearest the cursor
    empty='none'     # empty selection includes no data points

# define our base line chart of stock prices
base = alt.Chart().mark_line().encode(
    alt.Y('price:Q', scale=alt.Scale(type='log')),

    base, # base line chart
    # add a rule mark to serve as a guide line
    # add circle marks for selected time points, hide unselected points
        opacity=alt.condition(label, alt.value(1), alt.value(0))

    # add white stroked text to provide a legible background for labels
    base.mark_text(align='left', dx=5, dy=-5, stroke='white', strokeWidth=2).encode(

    # add text labels for stock prices
    base.mark_text(align='left', dx=5, dy=-5).encode(

Data Tables

You can display tables per the usual way in your blog:

movies = ''
df = pd.read_json(movies)
# display table with pandas
df[['Title', 'Worldwide_Gross', 
    'Production_Budget', 'Distributor', 'MPAA_Rating', 'IMDB_Rating', 'Rotten_Tomatoes_Rating']].head()
Title Worldwide_Gross Production_Budget Distributor MPAA_Rating IMDB_Rating Rotten_Tomatoes_Rating
0 The Land Girls 146083.0 8000000.0 Gramercy R 6.1 NaN
1 First Love, Last Rites 10876.0 300000.0 Strand R 6.9 NaN
2 I Married a Strange Person 203134.0 250000.0 Lionsgate None 6.8 NaN
3 Let's Talk About Sex 373615.0 300000.0 Fine Line None NaN 13.0
4 Slam 1087521.0 1000000.0 Trimark R 3.4 62.0


Local Images

You can reference local images and they will be copied and rendered on your blog automatically. You can include these with the following markdown syntax:


Remote Images

Remote images can be included with the following markdown syntax:


Animated Gifs

Animated Gifs work, too!



You can include captions with markdown images like this:

![]( "Credit:")

Other Elements

GitHub Flavored Emojis

Typing I give this post two :+1:! will render this:

I give this post two :+1:!


Typing > twitter: will render this:

Youtube Videos

Typing > youtube: will render this:

Boxes / Callouts

Typing > Warning: There will be no second warning! will render this:

Warning: There will be no second warning!

Typing > Important: Pay attention! It's important. will render this:

Important: Pay attention! It’s important.

Typing > Tip: This is my tip. will render this:

Tip: This is my tip.

Typing > Note: Take note of this. will render this:

Note: Take note of this.

Typing > Note: A doc link to [an example website:]( should also work fine. will render in the docs:

Note: A doc link to an example website: should also work fine.


You can have footnotes in notebooks, however the syntax is different compared to markdown documents. This guide provides more detail about this syntax, which looks like this:

For example, here is a footnote {% fn 1 %}.
And another {% fn 2 %}
{{ 'This is the footnote.' | fndetail: 1 }}
{{ 'This is the other footnote. You can even have a [link](!' | fndetail: 2 }}

For example, here is a footnote 1.

And another 2

1. This is the footnote.

2. This is the other footnote. You can even have a link!