In [1]:
import altair as alt
# remove when running on Colab or JupyterLab / add when running in a jupyter notebook
alt.renderers.enable('notebook')
Out[1]:
In [2]:
# Choose one of the two following data sets, the larger one gives better results, but might clutter the visualization depending on resolution
# !curl -O https://raw.githubusercontent.com/DJCordhose/ai/master/notebooks/scipy/data/insurance-customers-1500.csv
!curl -O https://raw.githubusercontent.com/DJCordhose/ai/master/notebooks/scipy/data/insurance-customers-300.csv
In [2]:
import pandas as pd
customers = pd.read_csv('./insurance-customers-300.csv', sep=';')
# customers = pd.read_csv('./insurance-customers-1500.csv', sep=';')
In [3]:
customers.head()
Out[3]:
In [4]:
alt.Chart(customers).mark_point().encode(
x='age',
y='max speed',
color='group')
Out[4]:
A bit more elaborateed
In [5]:
# https://altair-viz.github.io/user_guide/encoding.html
# https://altair-viz.github.io/user_guide/customization.html
alt.Chart(customers).mark_point().encode(
x='age',
y='max speed',
shape='group',
color=alt.Color('group',
type='nominal',
legend=alt.Legend(title="Type of Driver by Color"),
scale=alt.Scale(
range=['red', 'green', 'yellow'])),
).interactive()
Out[5]: