不显示以 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)
我正在尝试获取一个图表,其中填充了所有 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)