gpt4 book ai didi

python - 在 Bokeh 楔形图表上正确显示悬停工具提示

转载 作者:行者123 更新时间:2023-12-01 02:16:58 30 4
gpt4 key购买 nike

我正在尝试将悬停工具顶部添加到使用楔形字形制作的 Bokeh 饼图中,但悬停工具显示给定楔形的多个值。有办法纠正这个问题吗?代码是:

import numpy as np
from bokeh.plotting import figure
from bokeh.io import show, output_file
from bokeh.models import HoverTool, ColumnDataSource
from math import pi



percents = [0, 5/143, 51/143, 88/143, 108/143, 141/143, 1.0]
category = ['A ', 'B ', 'C ', 'D ', 'E ', 'F']
counts = [5, 46, 37, 20, 33, 2]
starts = [1/2*pi-(p*2*pi) for p in percents[:-1]]
ends = [1/2*pi-(p*2*pi) for p in percents[1:]]
colors = ['#889dba', '#1f356f', '#1e92b8', '#33748a', '#a5d3e3', '#bbc2d4']
# create source
source = ColumnDataSource(
data=dict(
x=[0 for x in percents],
y=[0 for x in percents],
radius = [0.5 for x in percents],
percents=percents,
category= category,
starts=starts,
colors=colors,
ends=ends,
counts = counts
)
)

TOOLS = "hover"

p = figure(plot_width = 500, plot_height = 500, x_axis_label = None, y_axis_label = None,
title = 'Type', tools = TOOLS)

p.title.align = 'center'
p.title.text_font = 'arial narrow'

p.wedge(x='x', y='y', radius = 'radius', direction="clock",
start_angle='starts', end_angle='ends', color='colors', source=source)

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


p.axis.visible = False
p.ygrid.visible = False
p.xgrid.visible = False

output_file(pie.html')
show(p)

这就是悬停时图片的样子: bokeh_pie

最佳答案

不久前我也遇到过类似的问题。老实说,我不知道这是一个错误还是我们实际上做错了什么。

您可以通过反转百分比列表(和标签)来临时解决该问题:

percents = percents[::-1]
category = category[::-1]
counts = counts[::-1]

然后从楔形中删除顺时针语句:

direction="clock",

关于python - 在 Bokeh 楔形图表上正确显示悬停工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48305017/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com