繁体   English   中英

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

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

我试图得到一个图表,其中填充了所有 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 个元素。 我希望找到一种方法来强制散景图显示所有值或达到相同效果的解决方法。

您可以显式设置绘图 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)

暂无
暂无

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

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