python - 未显示以 NaN Y 轴值开始或结束的散景图
问题描述
我试图得到一个图表,其中填充了所有 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)
推荐阅读
- c++ - 标签集的并行划分
- makefile - 终端匹配任何模式规则,多个先决条件
- python - int 和 tuple 之间的比较行为
- sql - 使列超出日期范围
- python-3.x - 如何生成逗号分隔列表并将列表从数据帧迭代到 API 字段?
- json - 试图找出一些 Javascript 从 JSON 响应中提取字段到 Zapier 中的原始 webhook 触发器
- angular - Angular - 寻找一种将组件注入另一个组件的方法
- c# - XMLWriter 尝试使用重复属性
- javascript - 涉及 ASCII 转换的凯撒密码公式问题
- javascript - 如果我使用慢速模式对象,Object.assign 的结果会处于字典模式吗?