2017-02-09 59 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