Python 如何根据Bokeh中的y填充不同颜色的区域

Python 如何根据Bokeh中的y填充不同颜色的区域,python,bokeh,Python,Bokeh,当y>=0时填充颜色应为绿色,当y时填充颜色应为红色VArea字形是连续的,但通过变换使y1和y2相同,只需将一些区域折叠为0区域块,就可以使填充颜色看起来像是独立的块 导入数学 从bokeh.models导入ColumnDataSource,CustomJSTransform 从bokeh.plotting导入图形,显示 从bokeh.transform导入transform N=100 ds=ColumnDataSource(dict(x=[i/10表示范围内的i(N)], y=[i在范围(

当y>=0时填充颜色应为绿色,当y时填充颜色应为红色
VArea
字形是连续的,但通过变换使
y1
y2
相同,只需将一些区域折叠为0区域块,就可以使填充颜色看起来像是独立的块

导入数学
从bokeh.models导入ColumnDataSource,CustomJSTransform
从bokeh.plotting导入图形,显示
从bokeh.transform导入transform
N=100
ds=ColumnDataSource(dict(x=[i/10表示范围内的i(N)],
y=[i在范围(N)内的数学sin(i/10)])
p=图()
p、 行('x','y',源=ds,线宽=3)
p、 varea(x='x',y1=transform('y',CustomJSTransform(v_func=“return xs.map(x=>x>0?x:0)”),
y2=0,震源=ds,颜色为绿色,填充字母=0.5)
p、 varea(x='x',y1=transform('y',CustomJSTransform(v_func=“return xs.map(x=>x<0?x:0)”),
y2=0,震源=ds,颜色为红色,填充字母=0.5)
表演(p)
from bokeh.plotting import figure, output_file, show
import numpy as np

strike1 = 20 #Long Call
premium1 = 0.5
price = np.arange(15,25,0.01)
contracts = 1

def long_call(price, strike1, premium1, contracts):
    P = []
    for i in price:
        P.append((max(i - strike1, 0) - premium1) * (contracts * 100))
    return np.array(P)


# output to static HTML file
output_file("lines.html")

# create a new plot with a title and axis labels
p = figure(title="Option Payoff", x_axis_label='Underlying Price ($)', y_axis_label='Profit/Loss ($)')

# add a line renderer with legend and line thickness
p.line(x, y, line_width=2)
p.varea(x=x, y1=y, fill_alpha=1, fill_color='#3cb371')

# show the results
show(p)