2017-02-09 53 views
2

我已加入到图像表示我的问题:创建具有双轴线的曲线图,但与范围不连接在一起,并用自动缩放

  1. 仅具有一个轴线和一个数据系列的曲线图。
  2. 两轴图(底部的线与第一个图中的线相同)。

我使用小部件和散景服务器为了让用户玩不同的选项显示不同的数据系列。

正如您在下面的代码中看到的,我已经在两个范围中都使用了DataRange1d,但即使在使用小部件更改方案时两个轴都会自动缩放,但这些轴会保持链接在一起,覆盖的范围相同有什么关系。

我在文档中搜索和唯一的解决方案,我发现我的问题是将一个特定的范围传递给Range1d或DataRange1d。我无法做到这一点,因为我有很多数据系列要展示,所以一个范围不适合所有人。

谢谢!

代码:

#create plots 
p_balance = figure(width=500, height=300, title='Balance', tools='save') 
p_total_debt = figure(width=500, height=300, title='Total debt', tools='save') 

p_both = figure(width=1000, height=300, title='Both', tools='save') 

#add the second axis 
p_both.y_range = DataRange1d() 
p_both.extra_y_ranges = {'total debt': DataRange1d()} 
p_both.add_layout(LinearAxis(y_range_name='total debt'), 'right') 

#add glyphs 
line_balance = p_balance.line(x=list(range(0,26)), y='y', source=source_balance, color='black', line_width=2) 
line_total_debt = p_total_debt.line(x=list(range(0,26)), y='y', source=source_total_debt, color='black', line_width=2) 

#for the second plot with both series 
line_balance2 = p_both.line(x=list(range(0,26)), y='y', source=source_balance, color='black', line_width=2) 
line_total_debt = p_both.line(x=list(range(0,26)), y='y', source=source_total_debt, color='black', line_width=2, y_range_name='total debt') 

图片1 Image 1

图片2 Image 2

回答

0

它为您提供一些初始值到Datarange对象就开始运行...... 我数据范围不能正确初始化,因此必须“手动”完成

我伪造数据,因为您没有提供任何数据。您可以使用min(your_data)max(your_data)来代替明确设置开始和结束值。

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

# create plots 
p_both = figure(width=1000, height=300, title='Both', tools='save', toolbar_sticky=False) 

# add the second axis 
p_both.y_range = Range1d(0, 26) 
p_both.extra_y_ranges = {'total_debt': Range1d(start=1000, end=1050)} 

# for the second plot with both series 
line_balance2 = p_both.line(x=range(0, 26), y=range(0, 26), color='black',  line_width=2) 
line_total_debt = p_both.line(x=range(0, 26), y=range(1000 + 0, 1000 + 26), color='red', line_width=2, 
          y_range_name='total_debt') 
p_both.add_layout(LinearAxis(y_range_name='total_debt'), 'right') 

show(p_both) 

enter image description here

+0

@etigrenier。这能解决你的问题吗? – renzop