y>;时填充颜色应为绿色=y<;时为0和红色=0您可以在Matplotlib中使用fill_between中的'when'变量执行此操作。博克有类似的功能吗
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)
VArea
图示符是连续的,但通过将y1
和y2
与变换相同,只需将一些区域折叠为0区域块,就可以使其看起来像是独立的块相关问题 更多 >
编程相关推荐