python - 散景中贝塞尔曲线之间的填充区域
问题描述
我正在尝试使用创建一个 sankey 图,bokeh
并且目前正在尝试弄清楚如何填充两条Bezier
曲线之间的区域。这是可能的还是有其他方法可以在不添加单个Bezier
字形的情况下实现这一点?
下面的示例代码——目标是用橙色填充曲线之间的区域。
from bokeh.models import Range1d, Plot, LinearAxis
from bokeh.models.glyphs import Bezier
from bokeh.io import show
plot = Plot(title=None, x_range=Range1d(0, 1), y_range=Range1d(-1, 1), plot_width=300, plot_height=300)
glyph = Bezier(x0=0, y0=0, x1=1, y1=1, cx0=0.5, cy0=0.01, cx1=0.5, cy1=0.99, line_color="orange", line_width=2)
glyph2 = Bezier(x0=0, y0=-1, x1=1, y1=0.5, cx0=0.5, cy0=-0.99, cx1=0.5, cy1=0.49, line_color="orange", line_width=2)
g1 = plot.add_glyph(glyph)
g2 = plot.add_glyph(glyph2)
xaxis = LinearAxis()
plot.add_layout(xaxis, 'below')
yaxis = LinearAxis()
plot.add_layout(yaxis, 'left')
show(plot)
解决方案
从 Bokeh0.13.0
开始,无法使用任何内置功能在两条 Bézier 曲线之间进行填充。目前,为了实现这一点,您必须编写某种自定义扩展类,该类使用您的输入数据绘制曲线并使用 HTML Canvas JavaScript API 进行填充。
否则,如果您能够将曲线表示为显式多段线而不是贝塞尔曲线,那么下一个最接近的就是Band
注释。假设具有 、 和 的数据框x
,y_mean
您y_std
可以执行以下操作:
df['lower'] = df.y_mean - df.y_std
df['upper'] = df.y_mean + df.y_std
source = ColumnDataSource(df.reset_index())
band = Band(base='x', lower='lower', upper='upper', source=source,
level='underlay', fill_alpha=1.0, line_width=1, line_color='black')
p.add_layout(band)
可以考虑添加一个更通用的波段,可以通过诸如贝塞尔曲线之类的东西来指定。随意提出GitHub 功能请求问题
推荐阅读
- botframework - Bot Framework 发送 OPTIONS 消息
- c# - “Microsoft.VisualStudio.QualityTools.UnitTestFramework”和“Microsoft.VisualStudio.TestPlatform.TestFramework”中都存在类型“TestClassAttribute”
- python-3.x - Python / Spyder - Contourf() 动画问题。速度和彩条。
- java - 如何检查 ArrayList 中的单词是否是文件中名称的子字符串,然后增加该单词的计数?
- mysql - 无法从另一个表中不存在的表中查询名称
- big-o - 对数方程中多项式的Big-O?
- python - sympy中和的指数乘以指数
- c# - JSON包含空对象时出现RestSharp错误
- c# - 联系表格不起作用,“值不能为空。参数名称:地址”MVC5
- jsf - PrimeFacess 只读属性有时会被禁用