在Python Bokeh中填充一行下面的区域

问题描述 投票:0回答:1

如何在Bokeh中的线下阴影区域?

我有一个简单的线条图,如下所示,我想用指定的颜色填充线下的。

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) 

因此,在下图中,它看起来像一个绿色区域。

enter image description here

我检查了Pathces字形功能,但是我不清楚。感谢任何帮助!

python bokeh
1个回答
1
投票

也许像:

band = Band(base='date', upper='cost', source=plot_source, level='underlay',
            fill_alpha=0.3, fill_color='green')
fig.add_layout(band)
© www.soinside.com 2019 - 2024. All rights reserved.