import altair as alt
import pandas as pd

penguins_df = pd.read_csv('data/penguins.csv')

# The base plot
base = alt.Chart(penguins_df).mark_bar().encode(
    alt.Y('species', title=None), alt.X('count()', title='Number of penguins'))
base

# Create added text
text = alt.Chart(____).____(____, ____).encode(alt.____('species'),
                                               alt.____('count()'),
                                               alt.____(____))

# Set up the title and subtitle formatting
penguin_title = alt.____(____, ____, ____, subtitleColor=____)

formatted_plot = (base + text).configure_view(____=0).properties(
    height=200, width=300, title=penguin_title)

formatted_plot
import altair as alt
import pandas as pd
from vega_datasets import data

# The data sources
gapminder_df = pd.read_csv('data/gapminder_codes.csv', parse_dates=['year'])
world_df = alt.____(data.world_110m.url, ____)

# The map
pop_dense_plot = (alt.Chart(____).____().encode(
    alt.____('____:Q',
             ____=alt.Scale(scheme=____, domainMid=____),
             title='Population Density (people/Km^2)')
).____(lookup='id', from_=alt.____(____, 'id', [____]))).properties(
    width=580,
    height=340,
    title='Country population densities are higher in Europe and parts of Asia'
).____(____=80, translate=[290, 240]).configure_legend(orient='bottom')

pop_dense_plot
Example #3
0
import altair as alt
import pandas as pd

penguins_df = pd.read_csv('data/penguins.csv')

# Obtain all the labels of the columns with dtype object in a list
# Name the list cat_cols
____ = ____

# Next create histogram pairplots for every categorical column
categorical_plots = alt.Chart(____).____().encode(
    alt.X(____, type=____), alt.Y(____, type=____), alt.____(____, title=None),
    alt.____(____,
             title=None)).____(____=____,
                               ____=____).resolve_scale(____='independent',
                                                        ____='independent')

____
import altair as alt
import pandas as pd

temps_df = pd.read_csv('data/temperature.csv', parse_dates=['date'])

temp_plot = alt.Chart(temps_df).____(____).encode(
    alt.X('date', ____), alt.Y('total_rain_mm', ____),
    alt.____(____, ____, ____)).properties(title=____)

temp_plot
Example #5
0
import altair as alt
import pandas as pd

penguins_df = pd.read_csv('data/penguins.csv')

colour_plot = alt.Chart(penguins_df).mark_point(____).encode(
    alt.X('flipper_length_mm', scale=____, title=____),
    alt.Y('body_mass_g', scale=____, title=____),
    alt.____('species', ____, ____), alt.____('species')).properties(____)

colour_plot
import altair as alt
import pandas as pd
from vega_datasets import data

# The data sources
world_df = alt.____(data.world_110m.url, ____)

# The map
world_plot = alt.Chart(____).____().____(type=____).properties(
    width=580, height=400, title='World Map')

world_plot
import altair as alt
import pandas as pd


penguins_df = pd.read_csv('data/penguins.csv')

slider = alt.____(name=.____, max=max(penguins_df.____))
select_rating = alt.____(
    fields=[____],
    bind=____)

slider_scatter = (alt.Chart(penguins_df).mark_circle().encode(
    alt.X('culmen_length_mm', title='Culmen length (mm)', scale=alt.Scale(zero=False)),
    alt.Y('culmen_depth_mm', title='Culmen depth (mm)', scale=alt.Scale(zero=False)),
    color='species',
    opacity=alt.condition(____ < ____, alt.value(0.7), alt.value(0.05)))
    .add_selection(____))

slider_scatter
Example #8
0
import altair as alt
import pandas as pd

pokemon_df = pd.read_csv('data/pokemon.csv')

pokemon_circleplot = alt.____(____).____().____(
    alt.X(____, ____), alt.Y(____, ____),
    alt.____(____, title='Number of Pokemon'),
    alt.____(____, title='Number of Pokemon')).____(
        title='Number of Pokemon types per generation')

____