示例#1
0
def test_barplot_stacked_net_line(plot_df):
    fig, ax = plt.subplots(figsize=(8, 8))
    # explicitly add negative contributions for net lines
    df = pyam.IamDataFrame(plot_df.data.copy())
    vals = [(2005, 0.35), (2010, -1.0), (2015, -4.0)]
    for i, (y, v) in enumerate(vals):
        newdata = [
            'test_model1', 'test_scenario1', 'World', 'Primary Energy|foo',
            'EJ/y', y, v
        ]
        df.data.loc[len(df) + i] = newdata
    df.filter(variable='Primary Energy|*', model='test_model1',
              scenario='test_scenario1', region='World')\
        .plot.bar(ax=ax, bars='variable', stacked=True)
    plotting.add_net_values_to_bar_plot(ax, color='r')
    return fig
示例#2
0
def test_barplot_stacked_net_line(plot_df):
    fig, ax = plt.subplots(figsize=(8, 8))
    # explicitly add negative contributions for net lines
    df = pyam.IamDataFrame(plot_df.data.copy())
    vals = [(2005, 0.35), (2010, -1.0), (2015, -4.0)]
    for i, (y, v) in enumerate(vals):
        newdata = [
            "test_model1",
            "test_scenario1",
            "World",
            "Primary Energy|foo",
            "EJ/y",
            y,
            v,
        ]
        df.data.loc[len(df) + i] = newdata
    df.filter(
        variable="Primary Energy|*",
        model="test_model1",
        scenario="test_scenario1",
        region="World",
    ).plot.bar(ax=ax, bars="variable", stacked=True)
    plotting.add_net_values_to_bar_plot(ax, color="r")
    return fig
示例#3
0
data = (df.filter(**args, variable='Emissions|CO2').filter(region='World',
                                                           keep=False))

data.plot.bar(bars='region',
              stacked=True,
              title='CO2 emissions by region',
              cmap='tab20')
plt.legend(loc=1)
plt.tight_layout()
plt.show()

###############################
# Add indicators to show net values
# *********************************
#
# Sometimes, stacked bar charts have negative entries.
# In that case, it helps to add a line showing the net value.

from pyam.plotting import add_net_values_to_bar_plot

fig, ax = plt.subplots()
data.plot.bar(ax=ax,
              bars='region',
              stacked=True,
              title='CO2 emissions by region',
              cmap='tab20')
add_net_values_to_bar_plot(ax)
plt.legend(loc=1)
plt.tight_layout()
plt.show()
示例#4
0
df = pyam.IamDataFrame(fname, encoding='ISO-8859-1')
print(df.head())

###############################
# We generated a simple stacked bar chart as below

data = df.filter({'variable': 'Emissions|CO2|*',
                  'level': 0,
                  'region': 'World',
                  'year': [2040, 2050, 2060]})

fig, ax = plt.subplots(figsize=(6, 6))
data.bar_plot(ax=ax, stacked=True)
fig.subplots_adjust(right=0.55)
plt.show()

###############################
# Sometimes stacked bar charts have negative entries - in that case it helps to
# add a line showing the net value.

data = df.filter({'variable': 'Emissions|CO2|*',
                  'level': 0,
                  'region': 'World',
                  'year': [2040, 2050, 2060]})

fig, ax = plt.subplots(figsize=(6, 6))
data.bar_plot(ax=ax, stacked=True)
add_net_values_to_bar_plot(ax, color='k')
fig.subplots_adjust(right=0.55)
plt.show()