环形楔形上的模糊提示:始终提供额外信息

2024-04-25 22:02:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我用annular_wedge字形在bokeh创建了下面的圆环图。我已经创建了一个工具提示,它正确地显示了每个按钮的百分比和类别,但始终包含一个额外的category : ???和{}

为什么会出现,我怎样才能去掉它?在

下面是一个指向用于生成绘图的笔记本的链接:link

enter image description here

# define starts/ends for wedges from percentages of a circle
percents = [0, 0.14, 0.22, 0.40, 0.83, 0.99, 1.0]
category = ['Extreme ', 'High ', 'Light ', 'Medium ', 'Not Classified', 'Very Light ']
starts = [p*2*pi for p in percents[:-1]]
ends = [p*2*pi for p in percents[1:]]

# a color for each pie piece
colors = brewer['Spectral'][len(percents)]

# create source
source = ColumnDataSource(
    data=dict(
        x=[0 for x in percents],
        y=[0 for x in percents],
        ymin = [0.5 for x in percents],
        ymax = [1 for x in percents],
        percents=percents,
        category= category,
        starts=starts,
        colors=colors,
        ends=ends,
    )
)

# create chart
TOOLS = "hover"
p = bk.figure(title='Chronic',title_text_font ='Roboto', title_text_font_size ='14pt', title_text_alpha =0.7,
              x_range=(-1.1,1.1), y_range=(-1.1,1.1), width=250, height=250, tools=TOOLS)

p.annular_wedge(x='x', y='y',  inner_radius='ymin', outer_radius='ymax', direction="anticlock",
                start_angle='starts', end_angle='ends', color='colors', source=source)

hover = p.select(dict(type=HoverTool))
hover.tooltips = [
    ('category', '@category'),
    ('percents','@percents')
]

# displays
bk.show(p)

Tags: textinsourcefortitlepilightcolors