Search code examples
pythonbokeh

simple 1 layer area chart in bokeh


I am trying to create a simple area chart in bokeh (1 layer)
My attempt

df_example = pd.DataFrame(data=  [['01-01-2018',10],['02-01-2018', 5 ], ['03-01-2018',7]], columns = ['date', 'value'] )

p = figure(plot_width=600, plot_height=400, x_range = df_example['date'])

p.Area(df_example, x='date', y='value') 

show(p)

I get an error

 AttributeError: 'Figure' object has no attribute 'Area'

Is the Area chart seems to be not available in bokeh anymore
Can anybody demonstrate how to get this type of chart please?


Solution

  • Bokeh recently added a varea_stack glyph method:

    from bokeh.models import ColumnDataSource
    from bokeh.plotting import figure, show
    
    source = ColumnDataSource(data=dict(
        x=[1, 2, 3, 4, 5],
        y1=[1, 2, 4, 3, 4],
        y2=[1, 4, 2, 2, 3],
    ))
    p = figure(plot_width=400, plot_height=400)
    
    p.varea_stack(['y1', 'y2'], x='x', color=("grey", "lightgrey"), source=source)
    
    show(p)
    

    enter image description here