我希望当我将鼠标悬停在每个点上时显示马力(“HP”)和重量(“吨”)的单位。 截至目前,它仅显示值(附图)。 我希望它显示,例如: 型号: 普利茅斯狂怒 重量:3785吨 生命值:95 生命值
这是我的代码:
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))
您还可以使用这个灵活的解决方案,它可以使用 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>
"""