Quick Viz with Altair

cereal
name mfr type calories ... shelf weight cups rating
0 100% Bran N Cold 70 ... 3 1.0 0.33 68.402973
1 100% Natural Bran Q Cold 120 ... 3 1.0 1.00 33.983679
2 All-Bran K Cold 70 ... 3 1.0 0.33 59.425505
... ... ... ... ... ... ... ... ... ...
74 Wheat Chex R Cold 100 ... 1 1.0 0.67 49.787445
75 Wheaties G Cold 100 ... 1 1.0 1.00 51.592193
76 Wheaties Honey Gold G Cold 110 ... 1 1.0 0.75 36.187559

77 rows × 16 columns

import altair as alt
chart0 = alt.Chart(cereal).mark_bar().encode(
    x='mfr',
    y='count()'
)
chart0
404 image
chart0 = alt.Chart(cereal).mark_bar().encode(
    x='mfr',
    y='count()'
)
chart0
alt.chart(...)...
alt.chart(cereal)
alt.chart(cereal).mark_bar()...
alt.chart(cereal).mark_bar().encode(
  x='mfr', 
  y='count()')
chart1 = alt.Chart(cereal, width=500, height=300).mark_bar().encode(
    x='mfr',
    y='count()'
)
chart1
404 image
chart2 = alt.Chart(cereal, width=500, height=300).mark_circle().encode(
    x='sugars',
    y='calories'
)
chart2
404 image
chart3 = alt.Chart(cereal, width=500, height=300).mark_circle(opacity=0.3).encode(
    x='sugars',
    y='calories'
)
chart3
404 image
chart4 = alt.Chart(cereal, width=500, height=300).mark_circle(color='red', opacity=0.3).encode(
    x='sugars',
    y='calories'
)
chart4
404 image
chart5 = alt.Chart(cereal, width=500, height=300).mark_circle(color='red', size=80, opacity=0.3).encode(
    x='sugars',
    y='calories'
)
chart5
404 image
chart6 = alt.Chart(cereal, width=500, height=300).mark_circle(color='red', size=80, opacity=0.3).encode(
    x='sugars',
    y='calories'
).properties(title="Scatter plot sugars vs calories for different cereals")
chart6
404 image

Let’s apply what we learned!