2017-10-13 77 views
0

我想提出一個情節以下的例子中發現here位置繪圖區域外的傳說與背景虛化

不幸的是,我有17條曲線,我需要顯示,和傳說重疊它們。我知道我可以創建一個圖例對象,它可以在繪圖區域外部顯示,如here,但是我有17條曲線,因此使用循環要方便得多。

你知道如何結合這兩種方法嗎?

回答

0

好的,我找到了解決方案。請參閱下面的代碼,我剛剛修改了交互式圖例示例:

import pandas as pd 
from bokeh.palettes import Spectral4 
from bokeh.plotting import figure, output_file, show 
from bokeh.sampledata.stocks import AAPL, IBM, MSFT, GOOG 
from bokeh.models import Legend 
from bokeh.io import output_notebook 

output_notebook() 

p = figure(plot_width=800, plot_height=250, x_axis_type="datetime", toolbar_location='above') 
p.title.text = 'Click on legend entries to mute the corresponding lines' 

legend_it = [] 

for data, name, color in zip([AAPL, IBM, MSFT, GOOG], ["AAPL", "IBM", "MSFT", "GOOG"], Spectral4): 
    df = pd.DataFrame(data) 
    df['date'] = pd.to_datetime(df['date']) 
    c = p.line(df['date'], df['close'], line_width=2, color=color, alpha=0.8, 
      muted_color=color, muted_alpha=0.2) 
    legend_it.append((name, [c])) 


legend = Legend(items=legend_it, location=(0, -60)) 
legend.click_policy="mute" 

p.add_layout(legend, 'right') 

show(p)