Esempio n. 1
0
def render(df: pd.DataFrame) -> Figure:
    from bokeh.models import HoverTool
    from bokeh.palettes import Category10_10
    from bokeh.plotting import ColumnDataSource
    p = Figure(plot_width=1200, plot_height=600, x_axis_type='datetime')
    names = [x for x in df.columns.tolist() if x not in ('date', 'zeros')]
    source = ColumnDataSource(df)
    p.varea_stack(stackers=names,
                  x='date',
                  color=Category10_10[:len(names)],
                  legend_label=names,
                  source=source)
    p.line(x='date', y='zeros', line_alpha=0, source=source)
    p.legend.location = 'top_left'
    p.add_tools(
        HoverTool(tooltips=[('date', '@date{%Y-%m-%d}')] + [(x, f'@{x}')
                                                            for x in names],
                  formatters={'@date': 'datetime'},
                  mode='vline'))
    return p