Python / Bokeh - 在对数尺度上绘制带有间隙的数据

时间:2015-07-21 19:03:09

标签: python bokeh

我正在使用Pandas - Bokeh中的数据集,其中有几个值为NaN的地方。制作标准散点图时,绘图界面只会遗漏包含NaN值的行。但是,当我将任一轴更改为对数刻度时,根本没有绘制任何点。可能导致这种情况的原因是什么?

1 个答案:

答案 0 :(得分:0)

这是目前已知的问题,已列为版本0.9.4的里程碑。看看这个主题:https://github.com/bokeh/bokeh/issues/2162

我遇到了类似的问题,所以作为一种解决方法,我将范围拆分为nan值并单独绘制每个集合。这是基于Bokeh的log scale exampleunutbu'sthis question的回答。

import numpy as np
from bokeh.plotting import figure, output_file, show
from bokeh.models import LogAxis, Range1d

def using_clump(a, b):
    return [a[s] for s in np.ma.clump_unmasked(np.ma.masked_invalid(b))]
def main():
    x = [0.1, 0.5, 1.0, 1.5, np.nan, 2.0, 2.5, 3.0]
    y = [10**xx for xx in x]
    output_file("log.html")

    p = figure(plot_width=400, plot_height=400,
           y_axis_type="log", y_range=(10**-1, 10**4))

    xdata = using_clump(x, x)
    ydata = using_clump(y, x)
    for i in range(0, len(xdata)):
        p.line(xdata[i], ydata[i], line_width=2)
        p.circle(xdata[i], ydata[i], fill_color="white", size=8)

    show(p)

enter image description here