“???”在散景中显示而不是变量值
"???" displaying in bokeh instead of variable values
我需要一些关于在 python 中使用散景的帮助。我想使用 hovertool 在交互式点图中显示两个变量。但是,我得到“???”而不是变量的值。因此,例如,我希望显示类型变量,而不是狗、猫、鸟等……显示“???”当我将鼠标悬停在点上时显示。
from bokeh.plotting import figure, show, output_notebook
from bokeh.tile_providers import get_provider, Vendors
get_provider(Vendors.CARTODBPOSITRON)
from bokeh.models import ColumnDataSource, HoverTool
source = ColumnDataSource(data=dict(
x=list(Pet_Data['Latitude']),
y=list(Pet_Data['Longitude']),
Type=list(Pet_Data['Type']),
Age=list(Pet_Data['Age'])))
hover = HoverTool(tooltips=[
("Age", "@Age"),
("Type","@Type")
])
p = figure(x_axis_type="mercator",
y_axis_type="mercator",
tools=[hover, 'wheel_zoom','save'])
p.add_tile(CARTODBPOSITRON)
p.circle(x='Age',
y='Type',
source=source,
size=2,
line_color="#FF0000",
fill_color="#FF0000",
fill_alpha=0.05)
output_notebook()
show(p)
@Age
表示 ColumnDataSource
中的 "display values from the "Age" 列。从上面看,您没有任何名为 "Age"(或 "Type")的列在您的数据源中。(您有列 "x"、"y"、"name" 和 "inspection",除此之外别无其他。)如果您想在悬停工具中使用这些列,您需要将它们添加到数据源。
我需要一些关于在 python 中使用散景的帮助。我想使用 hovertool 在交互式点图中显示两个变量。但是,我得到“???”而不是变量的值。因此,例如,我希望显示类型变量,而不是狗、猫、鸟等……显示“???”当我将鼠标悬停在点上时显示。
from bokeh.plotting import figure, show, output_notebook
from bokeh.tile_providers import get_provider, Vendors
get_provider(Vendors.CARTODBPOSITRON)
from bokeh.models import ColumnDataSource, HoverTool
source = ColumnDataSource(data=dict(
x=list(Pet_Data['Latitude']),
y=list(Pet_Data['Longitude']),
Type=list(Pet_Data['Type']),
Age=list(Pet_Data['Age'])))
hover = HoverTool(tooltips=[
("Age", "@Age"),
("Type","@Type")
])
p = figure(x_axis_type="mercator",
y_axis_type="mercator",
tools=[hover, 'wheel_zoom','save'])
p.add_tile(CARTODBPOSITRON)
p.circle(x='Age',
y='Type',
source=source,
size=2,
line_color="#FF0000",
fill_color="#FF0000",
fill_alpha=0.05)
output_notebook()
show(p)
@Age
表示 ColumnDataSource
中的 "display values from the "Age" 列。从上面看,您没有任何名为 "Age"(或 "Type")的列在您的数据源中。(您有列 "x"、"y"、"name" 和 "inspection",除此之外别无其他。)如果您想在悬停工具中使用这些列,您需要将它们添加到数据源。