简体   繁体   English

未显示以 NaN Y 轴值开始或结束的散景图

[英]Bokeh Graph Starting or Finishing with NaN Y-Axis Values Is Not Shown

I am trying to get a graph that has all of the x-axis values filled but starts with y-axis values that are NaN.我试图得到一个图表,其中填充了所有 x 轴值,但以 NaN 的 y 轴值开始。 It appears that the graph will start at the first real y-axis value.该图似乎将从第一个实际 y 轴值开始。 Here is the example:这是示例:

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)

This is the result:这是结果: 散景图

As you can see the first 2 elements of the x-axis array aren't shown.如您所见,未显示 x 轴数组的前 2 个元素。 I was hoping to find a way to force bokeh graph to show all values or a workaround to the same effect.我希望找到一种方法来强制散景图显示所有值或达到相同效果的解决方法。

You could explicitly set the start (or end) of the plot's x (or y) axis.您可以显式设置绘图 x(或 y)轴的开始(或结束)。 Like so:像这样:

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)

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

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