Python 为什么博克不在这里生成额外的y范围?

Python 为什么博克不在这里生成额外的y范围?,python,plot,charts,bokeh,multiple-axes,Python,Plot,Charts,Bokeh,Multiple Axes,我的Bokeh版本是0.12.13和Python 3.6.0 我修改了此处提供的示例代码: 我刚刚尝试添加一个额外的y范围 from bokeh.plotting import output_file, figure, show from bokeh.models import LinearAxis, Range1d x = [1,2,3,4,5] y = [1,2,3,4,5] y2 = [10,9,8,7,6] y3 = [23,24,25,26,27] output_file("tw

我的Bokeh版本是0.12.13和Python 3.6.0 我修改了此处提供的示例代码:

我刚刚尝试添加一个额外的y范围

from bokeh.plotting import output_file, figure, show
from bokeh.models import LinearAxis, Range1d

x = [1,2,3,4,5]
y = [1,2,3,4,5]
y2 = [10,9,8,7,6]
y3 = [23,24,25,26,27]

output_file("twin_axis.html")

p = figure(x_range=(0,6), y_range=(0,6))

p.circle(x, y, color="red")

p.extra_y_ranges = {"foo1": Range1d(start=0, end=11)}
p.circle(x, y2, color="blue", y_range_name="foo1")
p.add_layout(LinearAxis(y_range_name="foo1"), 'left')

p.extra_y_ranges = {"foo2": Range1d(start=21, end=31)}
p.circle(x, y3, color="green", y_range_name="foo2")
p.add_layout(LinearAxis(y_range_name="foo2"), 'right')

p.toolbar_location ="above"
show(p)
虽然原始代码运行良好,但我修改后的代码却不能。我不知道我犯了什么错误。我对博克有点陌生,所以请给我正确的方向。
编辑:添加第三个y轴时没有输出。但它只在左侧的两个轴上工作。

问题在于,您不是在添加另一个y范围,而是在将新词典重新分配给
p。额外的y范围
,您是在完全替换旧词典。当您添加的轴期望
“foo1”
范围存在时,这会导致问题,但您已经将其吹走了。以下代码按预期工作:

from bokeh.plotting import output_file, figure, show
from bokeh.models import LinearAxis, Range1d

x = [1,2,3,4,5]
y = [1,2,3,4,5]
y2 = [10,9,8,7,6]
y3 = [23,24,25,26,27]

output_file("twin_axis.html")

p = figure(x_range=(0,6), y_range=(0,6))

p.circle(x, y, color="red")

p.extra_y_ranges = {"foo1": Range1d(start=0, end=11)}
p.circle(x, y2, color="blue", y_range_name="foo1")
p.add_layout(LinearAxis(y_range_name="foo1"), 'left')

# CHANGES HERE: add to dict, don't replace entire dict
p.extra_y_ranges["foo2"] = Range1d(start=21, end=31)

p.circle(x, y3, color="green", y_range_name="foo2")
p.add_layout(LinearAxis(y_range_name="foo2"), 'right')

p.toolbar_location ="above"
show(p)

问题在于,您没有添加另一个y范围-通过将新词典重新分配给
p.extra_y_范围
,您正在完全替换旧词典。当您添加的轴期望
“foo1”
范围存在时,这会导致问题,但您已经将其吹走了。以下代码按预期工作:

from bokeh.plotting import output_file, figure, show
from bokeh.models import LinearAxis, Range1d

x = [1,2,3,4,5]
y = [1,2,3,4,5]
y2 = [10,9,8,7,6]
y3 = [23,24,25,26,27]

output_file("twin_axis.html")

p = figure(x_range=(0,6), y_range=(0,6))

p.circle(x, y, color="red")

p.extra_y_ranges = {"foo1": Range1d(start=0, end=11)}
p.circle(x, y2, color="blue", y_range_name="foo1")
p.add_layout(LinearAxis(y_range_name="foo1"), 'left')

# CHANGES HERE: add to dict, don't replace entire dict
p.extra_y_ranges["foo2"] = Range1d(start=21, end=31)

p.circle(x, y3, color="green", y_range_name="foo2")
p.add_layout(LinearAxis(y_range_name="foo2"), 'right')

p.toolbar_location ="above"
show(p)

不确定为什么有人投票关闭,这是一个完全合理的问题。不确定为什么有人投票关闭,这是一个完全合理的问题。啊!现在我了解了基本知识。非常感谢。谢谢你开发博克。我很喜欢它。如果你能投票和/或标记正确,我也会很感激:因为我没有“声誉”,所以不要投票,但标记正确。为什么现在左边有两个轴?如何删除其中一个?有两个轴,因为在上面的代码中明确添加了一个额外的轴。这就是问题的要点:“我如何添加一个额外的轴”啊!现在我了解了基本知识。非常感谢。谢谢你开发博克。我很喜欢它。如果你能投票和/或标记正确,我也会很感激:因为我没有“声誉”,所以不要投票,但标记正确。为什么现在左边有两个轴?如何删除其中一个?有两个轴,因为在上面的代码中明确添加了一个额外的轴。这就是问题的要点:“如何添加额外的轴”