为什么Bokeh在这里不产生额外的y范围? [英] Why isnt Bokeh generating extra y ranges here?

查看:133
本文介绍了为什么Bokeh在这里不产生额外的y范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My Bokeh version is 0.12.13 and Python 3.6.0 I modified the example code available here:

https://docs.bokeh.org/en/latest/docs/user_guide/plotting.html

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

I have just tried to add one extra y range.

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)

虽然原始代码运行良好,但我修改后的代码却没有.我无法弄清楚自己在犯什么错误.我对bokeh有点陌生,所以请向正确的方向引导. 当我添加第三个y轴时没有输出.但是它只能在左侧使用2个轴.

While the original code works well, my modified code doesnt. I am not able to figure out what mistake I am doing.I am a bit new to bokeh so please guide me in the right direction. There is no output when I add the third y axis. But it works with only 2 axes on the left side.

推荐答案

问题是您正在 not 添加另一个y范围—通过将新词典重新分配给p.extra_y_ranges,您可以完全 替换 .当您添加的轴期望存在"foo1"范围,但是您已经将其吹走时,这会导致问题.以下代码按预期工作:

The problem is that you are not adding another y-range — by reassigning a new dictionary to p.extra_y_ranges, you are replacing the old one, entirely. This causes problems when the axis you add expects the "foo1" range to exist, but you've blown it away. The following code works as expected:

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)

这篇关于为什么Bokeh在这里不产生额外的y范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆