是否可以在散景中设置工具提示格式以在列中的值后面包含文本?例如:在每个值后添加“吨”或“厘米”

问题描述 投票:0回答:1

我希望当我将鼠标悬停在每个点上时显示马力(“HP”)和重量(“吨”)的单位。 截至目前,它仅显示值(附图)。 我希望它显示,例如: 型号: 普利茅斯狂怒 重量:3785 生命值:95 生命值

https://i.stack.imgur.com/c7k5K.png

这是我的代码:

from bokeh.plotting import figure, output_notebook,show
from bokeh.models import ColumnDataSource as cds

output_notebook()
import seaborn as sns

mpg = sns.load_dataset('mpg')
mpg.head()

usa = mpg[mpg.origin == 'usa']
japan = mpg[mpg.origin == 'japan']
europe = mpg[mpg.origin == 'europe']

sourceU = cds(data=usa)
sourceJ = cds(data=japan)
sourceE = cds(data=europe)

tt = [('Model','@name'),('Weight','@weight'),('HP','@horsepower')]
#Is there a way to modify this line above to include the unit as an additional string after the column value?


fig1 = figure(x_axis_label = 'Weight',y_axis_label='HP',width=350,height=300,title="USA",tooltips=tt)
fig2 = figure(x_axis_label = 'Weight',y_axis_label='HP',width=350,height=300,title="Japan",tooltips=tt)
fig3 = figure(x_axis_label = 'Weight',y_axis_label='HP',width=350,height=300,title="Europe",tooltips=tt)

fig1.circle(x='weight',y='horsepower',source=sourceU)
fig2.circle(x='weight',y='horsepower',source=sourceJ)
fig3.circle(x='weight',y='horsepower',source=sourceE)

show(row(fig1,fig2,fig3))
python text format tooltip bokeh
1个回答
0
投票

您还可以使用这个灵活的解决方案,它可以使用 html 并更改颜色、字体等:

tt = f"""<b>The Model is </b> @name <br>
         <b>@weight</b> Tonnes (Weight) <br>
         <b>HP is </b> <font color="green">@horsepower HP</font> <br>
         """
© www.soinside.com 2019 - 2024. All rights reserved.