简体   繁体   English

基于 True/Fase 条件的散景线颜色

[英]Bokeh line color based on the True/Fase condition

I am trying to plot anomaly regions in Bokeh.我试图在散景中绘制异常区域。 The idea is to have a line that will use red color to show that those samples are anomalous ones.这个想法是有一条线,将使用红色来表明这些样本是异常的。

Here is a sample reproducible code.这是一个示例可重现代码。

import numpy as np
import random

n=300
dat = pd.DataFrame()
dat['X_axis'] = np.linspace(start=0.0, stop=1000, num = n)
mean = 4
std = 1
dat['Y_axis']=np.random.normal(loc=mean, scale=std, size = n)
dat['anom'] = np.random.choice([False, True ], size = (n,), p= [0.90, 0.10])

I was able to implement the Box Annotation, and I am trying to do the same thing but this time, the same region will just have a red color for that portion of the line.我能够实现 Box Annotation,并且我正在尝试做同样的事情,但是这一次,同一区域的那部分线将只有红色。

在此处输入图片说明

EDIT:编辑:

Following a comment/suggestion, I plotted those two lines as separate.根据评论/建议,我将这两行分开绘制。 However, Bokeh interpolates between values, instead of having a smooth transaction.但是,Bokeh 在值之间进行插值,而不是进行平滑的交易。 Is there a way to drop interpolation, or at least minimize between it to two adjacent values?有没有办法删除插值,或者至少将其最小化为两个相邻值?

在此处输入图片说明

EDIT 2:编辑2:

I was able to break it into individual segments.我能够将其分解为单独的部分。 However, now there are gaps between data samples that need to be eliminated.但是,现在需要消除数据样本之间的差距。 Any suggestion on how to do that?关于如何做到这一点的任何建议? 在此处输入图片说明

You will have to split your data up and use either multiple calls to line or a single call to multi_line .您将不得不拆分数据并使用多次调用line或一次调用multi_line It is not possible to specify different colors along different parts of a single line .不可能沿着一条line不同部分指定不同的颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM