[Python] Fill an area under a line in Python Bokeh

Discussão em 'Python' iniciado por Stack, Maio 5, 2025.

  1. Stack

    Stack Membro Participativo

    How to shade the area under a line in Bokeh?

    I have a simple line plot as follows and I want to fill an under a line in a specified color.

    import pandas as pd
    from bokeh.io import output_file, curdoc
    from bokeh.plotting import figure, show
    from bokeh.models import ColumnDataSource

    output_file("layout.html")


    df = pd.DataFrame({'date': ["1-1-2019", "2-1-2019", "3-1-2019", "4-1-2019", "5-1-2019", "6-1-2019", "7-1-2019", "8-1-2019", "9-1-2019", "10-1-2019"],
    'cost': [10, 15, 20, 30, 25, 5, 15, 30, 35, 25]})

    fig = figure(x_axis_type="datetime", toolbar_location='above', plot_width=1500)

    plot_source = ColumnDataSource(data=dict(date=pd.to_datetime(df["date"]),
    cost=df["cost"]))

    line_plot = fig.line("date", "cost", source=plot_source, line_width=2, color="#00CED1")

    show(fig)


    So it will look like a green area in the image below.

    [​IMG]

    I checked Pathces glyph function however I am not clear about it. Appreciate any help!

    Continue reading...

Compartilhe esta Página