簡體   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