def total_capacity_per_country():
    data = read_power_plants()
    data = join_on_iso_3(data, 'country', two_americas=False)
    capacity_per_country = data.groupby(['country']).sum()['capacity_mw']
    number_per_country = data.groupby(
        ['country']).count()['country_long'].reset_index()
    country_names = capacity_per_country.axes[0].to_frame().reset_index(
        drop=True)
    capacity_per_country = capacity_per_country.reset_index(drop=True)
    country_names['quantity'] = number_per_country['country_long']
    country_names['capacity_mw'] = capacity_per_country
    country_names = join_on_iso_3(country_names, 'country', two_americas=False)
    return country_names
def timeline():
    co = carbon_data().dropna()
    co = join_on_iso_3(co, 'Code')
    co = co.groupby(['Continent', 'Year']).sum().reset_index()
    important_year = [
        [1914, 1918, "#C0BCB5"],
        [1929, 1933, "#4A6C6F"],
        [1939, 1945, "#846075"],
        [1956, 1960, "#AF5D63"],
        [1989, 1992, "#ED474A"],
        [2008, 2010, "#9649CB"]
    ]
    fig = go.Figure()
    for c in get_continents():
        fig.add_trace(go.Scatter(**scatter_fig(co, c)))

    fig.update_yaxes(range=[0, 22 * 10 ** 9])
    fig.update_layout(
        xaxis=dict(
            autorange=True,
            rangeslider=dict(
                autorange=True)
        ),
        shapes=[shapes(*years) for years in important_year]
    )
    # fig.write_html('tmp3.html', auto_open=True)
    return plotly.offline.plot(figure_or_data=fig, include_plotlyjs=False, output_type='div')
Esempio n. 3
0
def map_scatter_plot():
    data = read_power_plants()
    power_plant_types = get_power_plants_types(data)
    data = join_on_iso_3(data, 'country')
    limits = [[1, 99], [100, 999], [1000, 9999], [10000, 99999]]

    data.sort_values('capacity_mw', ascending=False)
    data = set_new_limits(data)
    data = set_text_for_map_plot(data)

    fig = go.Figure()
    charts, charts_orders = set_charts(data, limits, power_plant_types)
    for c in charts:
        fig.add_trace(c)

    buttons = [
        dict(
            label=pp,
            method="update",
            args=[{
                "visible": set_visible_by_option(pp, charts_orders)
            }, {
                "title":
                f'Locations of {pp} Power Plants  in the World<br>(Hover Power Plant for Details)'
            }]) for pp in power_plant_types
    ]

    fig.update_layout(
        title=
        f'Locations of {power_plant_types[0]} Power Plants  in the World<br>(Hover Power Plant for Details)',
        updatemenus=[dict(active=0, buttons=buttons)])
    return plotly.offline.plot(figure_or_data=fig,
                               include_plotlyjs=False,
                               output_type='div')
Esempio n. 4
0
def main():
    co = carbon_data().dropna()
    co = join_on_iso_3(co, 'Code')
    min_year, max_year = 1850, co['Year'].max()
    for year in range(min_year, max_year):
        data = co[co['Year'] == year].dropna(subset=['Continent'])
        data = data[data['Annual CO2 emissions (tonnes)'] > 0]
        data['rank'] = data['Annual CO2 emissions (tonnes)'].rank()
def get_data_from_year(current_year):
    co = data_by_year(current_year)
    pop = get_pop_by_year(current_year)

    data = join_gdp_by_iso3(co, 'Code', current_year)
    data = join_on_iso_3(data, 'Code')
    data = data.join(pop.set_index("code_pop"), on='Code').dropna(
        subset=[str(current_year), 'Country Name', f'{str(current_year)}_pop'])
    data['co2_per_capta'] = data['Annual CO2 emissions (tonnes)'] / data[
        f'{str(current_year)}_pop']
    data['co2_per_capta_str'] = data['co2_per_capta'].map(
        '{:,.2f} Tonnes / per capta'.format)
    data[f'{str(current_year)}_pop_str'] = data[
        f'{str(current_year)}_pop'].map('{:,.0f}'.format)
    data[f"{str(current_year)}_str"] = data[str(current_year)].map(
        '${:,.2f}'.format)
    return data