本文介绍了是否有任何方法可以将叠加层添加到bokeh图上,从而基于x轴数据点突出显示某些区域.见下图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在x轴和y轴上绘制一些数据,这些数据给出了峰值.我想用多种颜色突出显示峰的某些区域.

I am plotting some data on x-axis and y-axis which gives peaks. I want to highlight certain areas of the peaks in multiple colors.

我能够获得该图,但是不知道如何在该图上添加叠加层

I was able to get the plot but have no clue on how to add overlays to the plot

https://jascoinc.com/wp -content/uploads/2013/12/UV-fraction-collection.png

推荐答案

您可以为此使用BoxAnnotation.优点之一是,它始终会覆盖图的整个高度.

You could use BoxAnnotation for this. One advantage is that it always span entire height of the plot.

from bokeh.plotting import figure, show
from bokeh.models import BoxAnnotation

p = figure(plot_width=400, plot_height=400)

p.line([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [1, 3, 2, 8, 2, 1, 2, 3, 1, 9, 1, 2], line_width=2)
b1 = BoxAnnotation(left=3, right = 5, fill_color = 'red', fill_alpha = 0.5)
b2 = BoxAnnotation(left=9, right = 11, fill_color = 'green', fill_alpha = 0.5)
p.add_layout(b1)
p.add_layout(b2)
p.text([4, 10], [0, 0], ['area1', 'area2'], y_offset = -10, x_offset = -20)
show(p)

这篇关于是否有任何方法可以将叠加层添加到bokeh图上,从而基于x轴数据点突出显示某些区域.见下图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 04:47