Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 用于图形中第二个绘图的Bokeh鼠标悬停工具_Python 3.x_Bokeh - Fatal编程技术网

Python 3.x 用于图形中第二个绘图的Bokeh鼠标悬停工具

Python 3.x 用于图形中第二个绘图的Bokeh鼠标悬停工具,python-3.x,bokeh,Python 3.x,Bokeh,所以我有一个条形图,上面有一条线。它工作得很好,只是我无法让hovertool处理添加的线图。我不知道如何完成下面的代码,使悬停工作的行。任何帮助都将不胜感激 from bokeh.plotting import figure, ColumnDataSource from bokeh.embed import components from bokeh.models import LinearAxis, Range1d, HoverTool def convert_to_categorical

所以我有一个条形图,上面有一条线。它工作得很好,只是我无法让hovertool处理添加的线图。我不知道如何完成下面的代码,使悬停工作的行。任何帮助都将不胜感激

from bokeh.plotting import figure, ColumnDataSource
from bokeh.embed import components
from bokeh.models import LinearAxis, Range1d, HoverTool

def convert_to_categorical(months):
    month_names = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
    return [month_names[m-1] for m in months]


def NetRevGraph(NetRev, Vol):

    # bar chart (hovering works fine)
    x1 = [int(i['Month']) for i in NetRev]
    y1 = [i['Amount'] for i in NetRev]
    m1 = convert_to_categorical(x1)
    tooltip_net_rev = [("Net Revenue", "$y"),]
    source_net_rev = ColumnDataSource(data=dict(x=m1, y=y1, ))
    p = figure(plot_width=500, plot_height=400, x_range=m1, tooltips=tooltip_net_rev)
    p.vbar(x='x', width=0.5, bottom=0, top='y', color="#B3DE69", source=source_net_rev)

    # add line graph (can seem to complete this so that hover works)
    x2 = [int(i['MonthNum']) for i in Vol]
    y2 = [i['Val'] for i in Vol]
    m2 = convert_to_categorical(x2)
    source_vol = ColumnDataSource(data=dict(x=m2, y=y2, ))
    tooltip_net_vol = [("Volume", "$y"), ]
    p.extra_y_ranges = {"Vol": Range1d(start=min(y2), end=max(y2))}
    p.add_tools()
    p.line(x='x', y='y', line_width=2, y_range_name="Vol", color="black", source=source_vol)
    p.add_layout(LinearAxis(y_range_name="Vol"), 'right')

我明白了。我必须对条和行使用add_tools方法来为两者添加HoverTool

更新了图,不带悬停参数。给条形图一个变量名,然后用它添加悬停工具

p = figure(plot_width=500, plot_height=400, x_range=m1)
bar = p.vbar(x='x', width=0.5, bottom=0, top='y', color="#B3DE69", source=source_net_rev)
p.add_tools(HoverTool(renderers=[bar], tooltips=tooltip_net_rev))
线图也是如此

line = p.line(x='x', y='y', line_width=2, y_range_name="Vol", color="black", source=source_vol)
p.add_tools(HoverTool(renderers=[line], tooltips=tooltip_net_vol))