0

我试图得到一个图表,其中填充了所有 x 轴值,但以 NaN 的 y 轴值开始。该图似乎将从第一个实际 y 轴值开始。这是示例:

from bokeh.plotting import figure, output_file, show

output_file("line.html")
p = figure(plot_width=400, plot_height=400)

# add a line renderer with a NaN
n = float('nan')
p.line(
    [1, 2, 3, 4, 5], # x-axis
    [n, n, 7, 2, 4], # y-axis
    line_width=2
)
show(p)

这是结果: 散景图

如您所见,未显示 x 轴数组的前 2 个元素。我希望找到一种方法来强制散景图显示所有值或达到相同效果的解决方法。

4

1 回答 1

1

您可以显式设置绘图 x(或 y)轴的开始(或结束)。像这样:

from bokeh.plotting import figure, output_file, show

output_file("line.html")
p = figure(plot_width=400, plot_height=400)

# add a line renderer with a NaN
n = float('nan')
x_values = [1, 2, 3, 4, 5]  # x-axis
y_values = [n, n, 7, 2, 4]  # y-axis
p.line(x=x_values, y=y_values, line_width=2)

# of course in real life it'd make sense to do max and min of x and y,
# but this is all we need for your specific example.
p.x_range.start = min(x_values)

show(p)
于 2020-11-27T21:42:01.753 回答