Python bokeh未渲染图形

Python bokeh未渲染图形,python,bokeh,Python,Bokeh,我正在尝试使用bokeh包使用hoovertool。我有以下代码: from bokeh.plotting import figure, output_file, show, ColumnDataSource from bokeh.models import HoverTool output_file("toolbar.html") source = ColumnDataSource(data=dict( x=[1, 2, 3, 4, 5], y=[2, 5, 8, 2, 7

我正在尝试使用bokeh包使用hoovertool。我有以下代码:

from bokeh.plotting import figure, output_file, show, ColumnDataSource
from bokeh.models import HoverTool

output_file("toolbar.html")

source = ColumnDataSource(data=dict(
    x=[1, 2, 3, 4, 5],
    y=[2, 5, 8, 2, 7],
    desc=['A', 'b', 'C', 'd', 'E'],
))

hover = HoverTool()

hover.tooltips = [
    ("index", "@index"),
    ("(x,y)", "(@x, @y)"),
    ("desc", "@desc"),
]

# create a new plot with a title and axis labels
p = figure(title="simple line example", x_axis_label='latitude', y_axis_label='longitude')

# Add circle glyphs to figure p
p.circle(x = 'x', y = 'x', size=10, fill_color="grey", line_color=None, 
         hover_fill_color="condition", hover_line_color="white", source = source)

# Create a HoverTool: hover
hover = HoverTool(tooltips=None, mode='vline')

# Add the hover tool to the figure p
p.add_tools(hover)

# Specify the name of the output file and show the result
output_file('hover_glyph.html')
show(p)
当代码运行时,会打开一个新选项卡,但不存在任何图形。我试过把球投进洞里

x = [1, 2, 3, 4, 5]; y = [2, 5, 8, 2, 7]
p.circle(x = 'x', y = 'x', size=10, fill_color="grey", line_color=None, 
         hover_fill_color="condition", hover_line_color="white", source = source)
我也看了前面的这些问题。但仍然无法让它发挥作用。另外,当我运行这个问题的代码时,一个图形呈现出来是没有问题的

谢谢你的帮助,干杯


Sandy

问题是您引用的ColumnDataSource条件中的列不存在。您的代码只需定义条件列表即可工作。代码中的另一个问题是您定义了两次hovertool,因此我还通过删除第一个来解决这个问题

#!/usr/bin/python3
from bokeh.plotting import figure, output_file, show, ColumnDataSource
from bokeh.models import HoverTool

output_file("toolbar.html")

source = ColumnDataSource(data=dict(
    x=[1, 2, 3, 4, 5],
    y=[2, 5, 8, 2, 7],
    desc=['A', 'b', 'C', 'd', 'E'],
    condition=['red', 'blue', 'pink', 'purple', 'grey']
))

# create a new plot with a title and axis labels
p = figure(title="simple line example", x_axis_label='latitude', y_axis_label='longitude')

# Add circle glyphs to figure p
p.circle(x = 'x', y = 'y', size=10, fill_color="grey", line_color=None, hover_fill_color="condition", hover_line_color="white", source = source)

hover = HoverTool(mode='vline')

hover.tooltips = [
    ("(x,y)", "(@x, @y)"),
    ("desc", "@desc")
]

# Add the hover tool to the figure p
p.add_tools(hover)

# Specify the name of the output file and show the result
output_file('hover_glyph.html')
show(p)