Exemplo n.º 1
0
def make_sector_fig(df, name, metadata):
    fig = PredictionFigure(
        sector_name=name,
        unit_name='kt',
        title=metadata['name'],
        smoothing=True,
        # allow_nonconsecutive_years=True,
        fill=True,
        stacked=True,
    )
    if len(df.columns) == 2:
        fig.add_series(df=df, trace_name='Päästöt', column_name='')
    else:
        fig.legend = True
        fig.legend_x = 0.8
        column_names = list(df.columns)
        column_names.remove('Forecast')
        colors = generate_color_scale(metadata['color'], len(column_names))
        for idx, col_name in enumerate(column_names):
            subsector = metadata['subsectors'][col_name]
            fig.add_series(df=df,
                           trace_name=subsector['name'],
                           column_name=col_name,
                           historical_color=colors[idx])
    return fig.get_figure()
Exemplo n.º 2
0
 def make_sector_fig(self, df, name, metadata, base_color):
     lang = get_active_locale()
     fig = PredictionFigure(
         sector_name=name,
         unit_name='kt',
         title=metadata.get('name_%s' % lang, metadata['name']),
         smoothing=True,
         # allow_nonconsecutive_years=True,
         fill=True,
         stacked=True,
     )
     if len(df.columns) == 2:
         fig.add_series(df=df,
                        trace_name=_('Emissions'),
                        column_name='',
                        historical_color=base_color)
     else:
         fig.legend = True
         fig.legend_x = 0.8
         column_names = list(df.columns)
         column_names.remove('Forecast')
         colors = generate_color_scale(base_color, len(column_names))
         for idx, col_name in enumerate(column_names):
             subsector = metadata['subsectors'][col_name]
             fig.add_series(df=df,
                            trace_name=subsector.get(
                                'name_%s' % lang, metadata['name']),
                            column_name=col_name,
                            historical_color=colors[idx])
     return fig.get_figure()