我根据他们的文档提供以下内容:
album_name
我想用x轴上的效价和y轴上的能量制作散点图。此外,当您将鼠标悬停在每个点上时,我希望它为album_name
说出它的值。并且该点的颜色基于from bokeh.models import ColumnDataSource, Range1d, LabelSet, Label
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
from bokeh.palettes import brewer
source = ColumnDataSource(data=dict(valence=valence,
energy=energy,
names=album_names))
p = figure()
p.scatter(x='valence', y='energy', size=8, source=source)
labels = LabelSet(x='valence', y='energy', text='names',
level='glyph', x_offset=5, y_offset=5,
source=source, render_mode='canvas')
p.add_layout(labels)
show(p)
。
我尝试了以下内容:
{{1}}
但是,当您将鼠标悬停在该点上时,这不会显示相册名称。它修复了该点旁边的专辑名称。任何帮助,只有当鼠标悬停在该点上并且根据album_name的值更改颜色时才能显示album_name
答案 0 :(得分:3)
检查一下它会起作用:
from bokeh.plotting import figure, ColumnDataSource, output_notebook, show
from bokeh.models import HoverTool, WheelZoomTool, PanTool, BoxZoomTool, ResetTool, TapTool, SaveTool
from bokeh.palettes import brewer
output_notebook()
#preprocessing the data with column album_name
category = 'album_name'
category_items = df[category].unique()
#selecting the colors for each unique category in album_name
palette = brewer['Set2'][len(category_items) + 1]
#mapping each category with a color of Set2
colormap = dict(zip(category_items, palette))
#making a color column based on album_name
df['color'] = df[category].map(colormap)
title = "Album_names"
#feeding data into ColumnDataSource
source = ColumnDataSource(df)
#Editing the hover that need to displayed while hovering
hover = HoverTool(tooltips=[('Album_name', '@album_name')])
#tools that are need to explote data
tools = [hover, WheelZoomTool(), PanTool(), BoxZoomTool(), ResetTool(), SaveTool()]
#finally making figure with scatter plot
p = figure(tools=tools,title=title,plot_width=700,plot_height=400,toolbar_location='right',toolbar_sticky=False, )
p.scatter(x='valence',y='energy',source=source,size=10,color='color',legend=category)
#displaying the graph
show(p)
答案 1 :(得分:2)
试试这个:
public WindowViewModel(Label userName)
{
var us = GetUser(u => u.Id == 1);
userName.Content = us.Name.ToString();
}
from bokeh.io import show
from bokeh.models import ColumnDataSource, HoverTool
from bokeh.plotting import figure
album_names = [...]
valence = [...]
energy = [...]
source = ColumnDataSource(data=dict(valence=valence,
energy=energy,
names=album_names))
p = figure(tools=[HoverTool(tooltips=[('Album Name', '@names'),
('Valence', '@valence'),
('Energy', '@energy')])])
p.scatter(x='valence', y='energy', size=8, source=source)
show(p)
显示所有工具提示,因此您必须添加它并配置它以显示您想要的内容。
您可以在documentation。