jha*_*oo8 3 python pandas bokeh
我有一个数据框,其中包含有玩家姓名和统计数据的列.我绘制了两个不同的统计数据,希望玩家名称出现在散点图上的每个点下面.
这是我到目前为止所做的,但它不起作用.对于文本,我假设这是我想要在图上每个点下面的名称列表,源是名称来自的位置.
p = Scatter(dt,x='off_rating',y='def_rating',title="Offensive vs. Defensive Eff",color="navy")
labels = LabelSet(x='off_rating',y='def_rating',text="player_name",source=dt)
p.add_layout(labels)
Run Code Online (Sandbox Code Playgroud)
Olu*_*ule 12
你走在正确的道路上.但是,sourcefor LabelSet必须是DataSource.这是一个示例代码.
from bokeh.plotting import show, ColumnDataSource
from bokeh.charts import Scatter
from bokeh.models import LabelSet
from pandas.core.frame import DataFrame
source = DataFrame(
dict(
off_rating=[66, 71, 72, 68, 58, 62],
def_rating=[165, 189, 220, 141, 260, 174],
names=['Mark', 'Amir', 'Matt', 'Greg', 'Owen', 'Juan']
)
)
scatter_plot = Scatter(
source,
x='off_rating',
y='def_rating',
title='Offensive vs. Defensive Eff',
color='navy')
labels = LabelSet(
x='off_rating',
y='def_rating',
text='names',
level='glyph',
x_offset=5,
y_offset=5,
source=ColumnDataSource(source),
render_mode='canvas')
scatter_plot.add_layout(labels)
show(scatter_plot)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4873 次 |
| 最近记录: |