import pandas as pd
import altair as alt
# we use sample data from this package
from vega_datasets import data
df = data.gapminder_health_income()
df.head()
alt.Chart(df).mark_point().encode(
    x='income',
    y='health'
)
df2 = data.iowa_electricity()
# while head displays the first rows, sample gives as a random selection:
df2.sample(5)
renewables_filter = df2["source"] == "Renewables"
renewables = df2[renewables_filter]
alt.Chart(renewables).mark_line().encode(
    x="year",
    y="net_generation",
)
alt.Chart(df2[df2["year"]=="2017"]).mark_arc().encode(    
    theta="net_generation",
    color="source"
)
alt.Chart(df2).mark_area().encode(
    x="year",
    y="net_generation",
    color="source"
)
alt.Chart(df).mark_bar().encode(
    x = alt.X('country'),
    y = alt.Y('population', scale=alt.Scale(type='log', zero=False)),
)
alt.Chart(df).mark_point().encode(
    alt.X('income').scale(type='log'),
    alt.Y('health').scale(zero=False),
)
alt.Chart(df).mark_point().encode(
    alt.X('income').scale(type='log'),
    alt.Y('health').scale(zero=False),
    alt.Size('population'),
)
alt.Chart(df2).mark_area().encode(
    alt.Color("source").scale(
        domain=["Renewables", "Nuclear Energy", "Fossil Fuels"],
        range=['green', 'red', 'purple']
    ),
    x="year",
    y="net_generation",
)
alt.Chart(df2).mark_line().encode(
    alt.Color("source").scale(
        domain=["Renewables", "Nuclear Energy", "Fossil Fuels"],
        range=['green', 'red', 'purple']
    ),
    x="year",
    y="net_generation"
)
alt.Chart(df).mark_point().encode(
    alt.X('income').scale(type='log'),
    alt.Y('health').scale(zero=False),
    alt.Opacity('population')
)
alt.Chart(df).mark_point(shape="square").encode(
    alt.X('income').scale(type='log'),
    alt.Y('health').scale(zero=False),
    alt.Opacity('population').scale(zero=False),
)